From 56afb8e1be342ee738db0bc8fb4d194c18264eee Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 13 Jun 2024 18:50:12 -0700 Subject: [PATCH] Merge missing part of Record deserialization support for 3.0/master --- .../tools/jackson/jr/ob/impl/BeanReader.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/jr-objects/src/main/java/tools/jackson/jr/ob/impl/BeanReader.java b/jr-objects/src/main/java/tools/jackson/jr/ob/impl/BeanReader.java index fc205790..ba8bc58d 100644 --- a/jr-objects/src/main/java/tools/jackson/jr/ob/impl/BeanReader.java +++ b/jr-objects/src/main/java/tools/jackson/jr/ob/impl/BeanReader.java @@ -31,6 +31,7 @@ public class BeanReader protected final BeanConstructors _constructors; + // @since 2.18 protected final boolean _isRecordType; // // 13-Dec-2017, tatu: NOTE! These will be constructed right after construction, but @@ -139,6 +140,29 @@ public BeanPropertyReader findProperty(String name) { public Object read(JSONReader r, JsonParser p) throws JacksonException { if (p.isExpectedStartObjectToken()) { + // [jackson-jr#148] Record deser support (2.18) + if (_isRecordType) { + final List values = new ArrayList<>(); + + String propName; + + // 13-Jun-2024, tatu: Should optimize the way _readBean() + // optimizes regular case... + for (; (propName = p.nextName()) != null;) { + BeanPropertyReader prop = findProperty(propName); + if (prop == null) { + handleUnknown(r, p, propName); + continue; + } + values.add(prop.getReader().readNext(r, p)); + } + try { + return _constructors.createRecord(values.toArray()); + } catch (Exception e) { + return _reportFailureToCreate(p, e); + } + } + final Object bean; try { bean = _constructors.create();