Skip to content

Add support for Jackson annotations#3736

Open
ZdravDimOracle wants to merge 15 commits intomicronaut-projects:5.0.xfrom
ZdravDimOracle:Dimitrije/json-view-jackson
Open

Add support for Jackson annotations#3736
ZdravDimOracle wants to merge 15 commits intomicronaut-projects:5.0.xfrom
ZdravDimOracle:Dimitrije/json-view-jackson

Conversation

@ZdravDimOracle
Copy link
Copy Markdown
Contributor

@ZdravDimOracle ZdravDimOracle commented Feb 27, 2026

This pull request adds support for flex columns and unnest keyword via Jackson annotations.

For flex columns we use @JsonAnyGetter and @JsonAnySetter annotations.
If we want to specify a property as a flex column, we use any of these annotations two on a property, also at most one property can have any combination of these two annotations, since there can only be one flex column.

Example:

@JsonView(entity = Person.class)
public class PersonView {
	@Id
	@GeneratedValue(GeneratedValue.Type.IDENTITY)
	private Long id;
	private String firstname;
	private String lastname;

	@JsonAnyGetter
	@JsonAnySetter
	private Map<String, Object> extras;
}

This creates a view like so:

CREATE OR REPLACE JSON RELATIONAL DUALITY VIEW person_view 
AS SELECT JSON {
    '_id': p.id,
	'firstname': p.firstname,
    'lastname': p.lastname,
    p.extras AS FLEX COLUMN
}
FROM TBL_PERSON p
WITH UPDATE INSERT DELETE;

For the unnest feature, we use @JsonUnwrapped annotation to specify which property will be unnested.

Example:

@JsonSubView(entity = Apartment.class, alias = "asw")
public record ApartmentSubView(
    @EmbeddedId
    @JsonUnwrapped
    ApartmentId apartmentId
) {}
@JsonView(entity = Building.class, alias = "bw")
public class BuildingView {
    @Id
    @GeneratedValue(GeneratedValue.Type.IDENTITY)
    private Long id;

    @Relation(Relation.Kind.ONE_TO_MANY)
    private List<ApartmentSubView> apartments;
}

This will create a JSON Duality View like so:

CREATE OR REPLACE JSON RELATIONAL DUALITY VIEW building_view
AS SELECT JSON {
	'_id': b.id,
	UNNEST (
		SELECT JSON {
			'apartments': [
				SELECT JSON {
					'buildingId': ap.building_id,
					'flatId': ap.flat_id
				}
				FROM TBL_APARTMENT ap
				WITH UPDATE INSERT DELETE
				WHERE building_apartment."APARTMENT_APARTMENT_ID_BUILDING_ID"=ap."BUILDING_ID"
				AND building_apartment."APARTMENT_APARTMENT_ID_FLAT_ID"=ap."FLAT_ID"
			]
		}
		FROM building_apartment ba
		WITH UPDATE INSERT DELETE
		WHERE b."ID"=building_apartment."BUILDING_ID"
		)
	}
	FROM TBL_BUILDING b
	WITH UPDATE INSERT DELETE;

@graemerocher
Copy link
Copy Markdown
Contributor

we need to clearly document which Jackson annotations are supported and how they map to duality views in the duality views section of the docs

@ZdravDimOracle ZdravDimOracle changed the title Dimitrije/json view jackson [Dimitrije] Add support for Jackson annotations Mar 4, 2026
@ZdravDimOracle ZdravDimOracle changed the title [Dimitrije] Add support for Jackson annotations Add support for Jackson annotations Mar 4, 2026
@dstepanov
Copy link
Copy Markdown
Contributor

Any specific Jackson support should be part of Serde

@graemerocher
Copy link
Copy Markdown
Contributor

@dstepanov serde doesn't make sense this context, it is about the mapping from java class to duality view. Which does use serde under the covers for runtime marshalling but this PR makes it also take into account for schema generation of the views

@ZdravDimOracle ZdravDimOracle marked this pull request as ready for review April 1, 2026 13:46
@andriy-dmytruk andriy-dmytruk requested review from andriy-dmytruk, dstepanov and graemerocher and removed request for andriy-dmytruk and graemerocher April 1, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants