Skip to content

feat: to(Record) with embedded records #94

@jbee

Description

@jbee

Feature

When accessing an object as record using to(Class) the record accessor should support record components that are not nested in terms of the input JSON. When such a component is marked (e.g. with an annotation) the name of the component is irrelevant as the same JSON object of the outer record is given to the inner record. This allows to map a "flat" JSON object to a structured "tree" of records. This is mostly useful and needed as records do not allow composition by inheritance. With this they can allow for composition by reusing structures as nested components.

Implementation

It might be as easy as checking for the marker in JsonAccess#accessAsRecord and if the marker is present instead of

 JsonMixed cValue = obj.get(c.getName());

the component JSON value is simply

 JsonMixed cValue = obj;

So together

 JsonMixed cValue = hasMarker(c) ? obj : obj.get(c.getName());

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions