Skip to content

Commit 893468e

Browse files
authored
Fix kotlin#308 issue (#5460)
1 parent 2011c86 commit 893468e

File tree

7 files changed

+26
-37
lines changed

7 files changed

+26
-37
lines changed

src/main/java/tools/jackson/databind/JavaType.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,8 @@ public final boolean isEnumImplType() {
305305
return ClassUtil.isEnumType(_class) && (_class != Enum.class);
306306
}
307307

308-
/**
309-
* @since 2.12
310-
*/
311308
public final boolean isRecordType() {
312-
return ClassUtil.isRecordType(_class);
309+
return _class.isRecord();
313310
}
314311

315312
/**

src/main/java/tools/jackson/databind/cfg/MapperConfigBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ public final VisibilityChecker getDefaultVisibilityChecker(Class<?> baseType,
622622

623623
if (ClassUtil.isJDKClass(baseType)) {
624624
vc = VisibilityChecker.allPublicInstance();
625-
} else if (ClassUtil.isRecordType(baseType)) {
625+
} else if (baseType.isRecord()) {
626626
// 15-Jan-2023, tatu: [databind#3724] Records require slightly different defaults
627627
vc = _configOverrides.getDefaultRecordVisibility();
628628
} else {

src/main/java/tools/jackson/databind/deser/bean/BeanDeserializer.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,10 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
564564
: creator.startBuilding(p, ctxt, _objectIdReader);
565565
TokenBuffer unknown = null;
566566
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null;
567-
568567
JsonToken t = p.currentToken();
569568
List<BeanReferring> referrings = null;
569+
final boolean isRecord = _beanType.isRecordType();
570+
570571
for (; t == JsonToken.PROPERTY_NAME; t = p.nextToken()) {
571572
String propName = p.currentName();
572573
p.nextToken(); // to point to value
@@ -576,14 +577,6 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
576577
continue;
577578
}
578579

579-
// [databind#4629] Need to check for ignored properties BEFORE checking for Creator properties.
580-
// Records (and other creator-based types) will have a valid 'creatorProp', so if we don't
581-
// check for ignore first, the ignore configuration will be bypassed.
582-
if (IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) {
583-
handleIgnoredProperty(p, ctxt, handledType(), propName);
584-
continue;
585-
}
586-
587580
// Creator property?
588581
if (creatorProp != null) {
589582
if ((activeView != null) && !creatorProp.visibleInView(activeView)) {
@@ -596,13 +589,21 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
596589
p.skipChildren();
597590
continue;
598591
}
592+
// [databind#4629] Need to check for ignored properties for Creator properties since
593+
// Records will have a valid 'creatorProp', so if we don't
594+
// check for ignore first, the ignore configuration will be bypassed.
595+
if (isRecord && IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) {
596+
handleIgnoredProperty(p, ctxt, handledType(), propName);
597+
continue;
598+
}
599599
// Last creator property to set?
600600
// [databind#4690] cannot quit early as optimization any more
601601
// if (buffer.assignParameter(creatorProp, value)) { ... build ... }
602602
buffer.assignParameter(creatorProp,
603603
_deserializeWithErrorWrapping(p, ctxt, creatorProp));
604604
continue;
605605
}
606+
606607
// regular property? needs buffering
607608
int ix = _propNameMatcher.matchName(propName);
608609
if (ix >= 0) {
@@ -1017,6 +1018,7 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
10171018
TokenBuffer tokens = ctxt.bufferForInputBuffering(p);
10181019
tokens.writeStartObject();
10191020

1021+
final boolean isRecord = _beanType.isRecordType();
10201022
JsonToken t = p.currentToken();
10211023
for (; t == JsonToken.PROPERTY_NAME; t = p.nextToken()) {
10221024
String propName = p.currentName();
@@ -1028,21 +1030,20 @@ protected Object deserializeUsingPropertyBasedWithUnwrapped(JsonParser p, Deseri
10281030
continue;
10291031
}
10301032

1031-
// Things marked as ignorable should not be passed to any setter
1032-
// [databind#4629] Need to check for ignored properties BEFORE checking
1033-
// for Creator properties.
1034-
if (IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) {
1035-
handleIgnoredProperty(p, ctxt, handledType(), propName);
1036-
continue;
1037-
}
10381033
if (creatorProp != null) {
10391034
// [databind#1381]: if useInput=FALSE, skip deserialization from input
10401035
if (creatorProp.isInjectionOnly()) {
10411036
// Skip the input value, will be injected later in PropertyValueBuffer
10421037
p.skipChildren();
10431038
continue;
10441039
}
1045-
1040+
// [databind#4629] Need to check for ignored properties for Creator properties since
1041+
// Records will have a valid 'creatorProp', so if we don't
1042+
// check for ignore first, the ignore configuration will be bypassed.
1043+
if (isRecord && IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) {
1044+
handleIgnoredProperty(p, ctxt, handledType(), propName);
1045+
continue;
1046+
}
10461047
// Last creator property to set?
10471048
// [databind#4690] cannot quit early as optimization any more
10481049
// if (buffer.assignParameter(creatorProp, value)) { ... build ... }

src/main/java/tools/jackson/databind/util/ClassUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ public static boolean isBogusClass(Class<?> cls) {
238238

239239
/**
240240
* Helper method for detecting Java14-added {@code Record} types
241+
*
242+
* @deprecated Since 3.1 Just call {@code Class.isRecord()}
241243
*/
244+
@Deprecated
242245
public static boolean isRecordType(Class<?> cls) {
243246
return cls.isRecord();
244247
}

src/main/java/tools/jackson/databind/util/NativeImageUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static boolean needsReflectionConfiguration(Class<?> cl) {
6060
return false;
6161
}
6262
// records list their fields but not other members
63-
return (cl.getDeclaredFields().length == 0 || ClassUtil.isRecordType(cl)) &&
63+
return (cl.getDeclaredFields().length == 0 || cl.isRecord()) &&
6464
cl.getDeclaredMethods().length == 0 &&
6565
cl.getDeclaredConstructors().length == 0;
6666
}

src/test/java/tools/jackson/databind/tofix/KotlinIssue308JsonIgnoreTest.java renamed to src/test/java/tools/jackson/databind/interop/KotlinIssue308JsonIgnoreTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tools.jackson.databind.tofix;
1+
package tools.jackson.databind.interop;
22

33
import org.junit.jupiter.api.Test;
44

@@ -7,7 +7,6 @@
77
import com.fasterxml.jackson.annotation.JsonProperty;
88

99
import tools.jackson.databind.ObjectMapper;
10-
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;
1110

1211
import static org.junit.jupiter.api.Assertions.*;
1312
import static tools.jackson.databind.testutil.DatabindTestUtil.*;
@@ -41,14 +40,13 @@ void unpackId(Integer idObj) {
4140

4241
private final ObjectMapper MAPPER = newJsonMapper();
4342

44-
@JacksonTestFailureExpected
4543
@Test
4644
public void testJsonIgnoreWithJsonPropertyUnpacker() throws Exception
4745
{
4846
TestDto dto = MAPPER.readValue("{\"id\":12345}", TestDto.class);
4947

5048
assertNotNull(dto);
51-
assertEquals(Integer.valueOf(12345), dto.cityId);
5249
assertNull(dto.id);
50+
assertEquals(Integer.valueOf(12345), dto.cityId);
5351
}
5452
}

src/test/java/tools/jackson/databind/records/RecordBasicsTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import tools.jackson.databind.json.JsonMapper;
1515
import tools.jackson.databind.testutil.DatabindTestUtil;
1616
import tools.jackson.databind.type.TypeFactory;
17-
import tools.jackson.databind.util.ClassUtil;
1817
import tools.jackson.databind.util.Converter;
1918

2019
import static org.junit.jupiter.api.Assertions.*;
@@ -67,15 +66,6 @@ record RecordAllWriteOnly(
6766
/**********************************************************************
6867
*/
6968

70-
@Test
71-
public void testClassUtil() {
72-
assertFalse(ClassUtil.isRecordType(getClass()));
73-
74-
assertTrue(ClassUtil.isRecordType(SimpleRecord.class));
75-
assertTrue(ClassUtil.isRecordType(RecordOfRecord.class));
76-
assertTrue(ClassUtil.isRecordType(RecordWithRename.class));
77-
}
78-
7969
@Test
8070
public void testRecordJavaType() {
8171
assertFalse(MAPPER.constructType(getClass()).isRecordType());

0 commit comments

Comments
 (0)