diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanConstructors.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanConstructors.java index 040dff12..0cf07735 100644 --- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanConstructors.java +++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanConstructors.java @@ -14,9 +14,6 @@ public class BeanConstructors protected Constructor _noArgsCtor; - // @since 2.18 - protected Constructor _recordCtor; - protected Constructor _intCtor; protected Constructor _longCtor; protected Constructor _stringCtor; @@ -30,12 +27,6 @@ public BeanConstructors addNoArgsConstructor(Constructor ctor) { return this; } - // @since 2.18 - public BeanConstructors addRecordConstructor(Constructor ctor) { - _recordCtor = ctor; - return this; - } - public BeanConstructors addIntConstructor(Constructor ctor) { _intCtor = ctor; return this; @@ -55,9 +46,6 @@ public void forceAccess() { if (_noArgsCtor != null) { _noArgsCtor.setAccessible(true); } - if (_recordCtor != null) { - _recordCtor.setAccessible(true); - } if (_intCtor != null) { _intCtor.setAccessible(true); } @@ -76,14 +64,6 @@ protected Object create() throws Exception { return _noArgsCtor.newInstance((Object[]) null); } - // @since 2.18 - protected Object createRecord(Object[] components) throws Exception { - if (_recordCtor == null) { - throw new IllegalStateException("Class "+_valueType.getName()+" does not have record constructor to use"); - } - return _recordCtor.newInstance(components); - } - protected Object create(String str) throws Exception { if (_stringCtor == null) { throw new IllegalStateException("Class "+_valueType.getName()+" does not have single-String constructor to use"); diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java index 1a138515..34e439a4 100644 --- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java +++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java @@ -68,8 +68,6 @@ private POJODefinition _introspectDefinition(Class beanType, } else if (argType == Long.class || argType == Long.TYPE) { constructors.addLongConstructor(ctor); } - } else if (RecordsHelpers.isRecordConstructor(beanType, ctor, propsByName)) { - constructors.addRecordConstructor(ctor); } } } diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java index 92938dc0..c07974b3 100644 --- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java +++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanReader.java @@ -36,8 +36,6 @@ public class BeanReader */ protected final BeanConstructors _constructors; - protected final boolean _isRecordType; - /** * Constructors used for deserialization use case * @@ -58,7 +56,6 @@ public BeanReader(Class type, Map props, aliasMapping = Collections.emptyMap(); } _aliasMapping = aliasMapping; - _isRecordType = RecordsHelpers.isRecordType(type); } @Deprecated // since 2.17 @@ -158,22 +155,6 @@ public Object read(JSONReader r, JsonParser p) throws IOException return _constructors.create(p.getLongValue()); case START_OBJECT: { - // [jackson-jr#148] Record deser support (2.18) - if (_isRecordType) { - final List values = new ArrayList<>(); - - String propName; - for (; (propName = p.nextFieldName()) != null;) { - BeanPropertyReader prop = findProperty(propName); - if (prop == null) { - handleUnknown(r, p, propName); - continue; - } - values.add(prop.getReader().readNext(r, p)); - } - return _constructors.createRecord(values.toArray()); - } - // If not Record, need to use default (no-args) Constructors Object bean = _constructors.create(); String propName; final Object[] valueBuf = r._setterBuffer; diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/ValueReaderLocator.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/ValueReaderLocator.java index f5f4a664..3a2b94e5 100644 --- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/ValueReaderLocator.java +++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/ValueReaderLocator.java @@ -473,25 +473,16 @@ protected BeanReader _resolveBeanForDeser(Class raw, POJODefinition beanDef) setter = null; } } - if (RecordsHelpers.isRecordType(raw)) { - try { - field = raw.getDeclaredField(rawProp.name); - } catch (NoSuchFieldException e) { - throw new IllegalStateException("Cannot access field '" + rawProp.name - + "' of record class `" + raw.getName() + "`", e); + // if no setter, field would do as well + if (setter == null) { + if (field == null) { + continue; } - } else { - // if no setter, field would do as well - if (setter == null) { - if (field == null) { - continue; - } - // fields should always be public, but let's just double-check - if (forceAccess) { - field.setAccessible(true); - } else if (!Modifier.isPublic(field.getModifiers())) { - continue; - } + // fields should always be public, but let's just double-check + if (forceAccess) { + field.setAccessible(true); + } else if (!Modifier.isPublic(field.getModifiers())) { + continue; } } diff --git a/jr-record-test/src/test-jdk17/java/jr/Java17RecordTest.java b/jr-record-test/src/test-jdk17/java/jr/Java17RecordTest.java index 84c9e81c..2a5d14de 100644 --- a/jr-record-test/src/test-jdk17/java/jr/Java17RecordTest.java +++ b/jr-record-test/src/test-jdk17/java/jr/Java17RecordTest.java @@ -14,23 +14,9 @@ public class Java17RecordTest extends TestCase public record Cow(String message, Map object) { } - // [jackson-jr#94] + // [jackson-jr#94]: Record serialization public void testJava14RecordSerialization() throws Exception { - JSON json = JSON.std; - var expectedDoc = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}"; - Cow input = new Cow("MOO", Map.of("Foo", "Bar")); - - assertEquals(expectedDoc, json.asString(input)); - } - - // [jackson-jr#148] - public void testJava14RecordDeserialization() throws Exception { - JSON json = JSON.std; - String inputDoc = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}"; - - Cow expected = new Cow("MOO", Map.of("Foo", "Bar")); - - Cow actual = json.beanFrom(Cow.class, inputDoc); - assertEquals(expected, actual); + assertEquals("{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}", + JSON.std.asString(new Cow("MOO", Map.of("Foo", "Bar")))); } } diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index f4ae32e2..42d9bbc1 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -64,8 +64,3 @@ Julian Honnen (@jhonnen) * Contributed fix for #90: `USE_BIG_DECIMAL_FOR_FLOATS` feature not working when using `JSON.treeFrom()` (2.17.1) - -Tomasz Gawęda (@TomaszGaweda) - -* Contributed #148: Add support for Java Record deserialization - (2.18.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index ce9f43a7..a2354c67 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -13,8 +13,7 @@ Modules: 2.18.0 (not yet released) -#148: Add support for Java Record deserialization - (contributed by Tomasz G) +- 2.17.1 (04-May-2024)