generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multi-level JSON unwrapped (#532)
Adds support for nesting `@JsonUnwrapped` declarations. --------- Co-authored-by: yawkat <jonas.konrad@oracle.com> --------- Co-authored-by: Radovan Radic <radovan.radic@oracle.com> Co-authored-by: yawkat <jonas.konrad@oracle.com> Co-authored-by: radovanradic <radicr@gmail.com>
- Loading branch information
1 parent
59512d7
commit 9cc2998
Showing
9 changed files
with
479 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
serde-jackson/src/test/java/io/micronaut/serde/jackson/nested/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.micronaut.serde.jackson.nested; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
@Serdeable | ||
public class Address { | ||
|
||
@JsonUnwrapped(prefix = "cd_") | ||
private CityData cityData = new CityData(); | ||
|
||
private String street; | ||
|
||
public String getStreet() { | ||
return street; | ||
} | ||
|
||
public void setStreet(String street) { | ||
this.street = street; | ||
} | ||
|
||
public CityData getCityData() { | ||
return cityData; | ||
} | ||
|
||
public void setCityData(CityData cityData) { | ||
this.cityData = cityData; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
serde-jackson/src/test/java/io/micronaut/serde/jackson/nested/Audit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.micronaut.serde.jackson.nested; | ||
|
||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.Date; | ||
|
||
@Serdeable | ||
public class Audit { | ||
|
||
static final Timestamp MIN_TIMESTAMP = new Timestamp(new Date(0).getTime()); | ||
|
||
private Long version = 1L; | ||
|
||
// Init manually because cannot be nullable and not getting populated by the event | ||
private Timestamp dateCreated = MIN_TIMESTAMP; | ||
|
||
private Timestamp dateUpdated = MIN_TIMESTAMP; | ||
|
||
public Long getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(Long version) { | ||
this.version = version; | ||
} | ||
|
||
public Timestamp getDateCreated() { | ||
return dateCreated; | ||
} | ||
|
||
public void setDateCreated(Timestamp dateCreated) { | ||
this.dateCreated = dateCreated; | ||
} | ||
|
||
public Timestamp getDateUpdated() { | ||
return dateUpdated; | ||
} | ||
|
||
public void setDateUpdated(Timestamp dateUpdated) { | ||
this.dateUpdated = dateUpdated; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
serde-jackson/src/test/java/io/micronaut/serde/jackson/nested/CityData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.micronaut.serde.jackson.nested; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
@Serdeable | ||
public class CityData { | ||
|
||
@NonNull | ||
private String zipCode; | ||
|
||
private String city; | ||
|
||
public String getZipCode() { | ||
return zipCode; | ||
} | ||
|
||
public void setZipCode(String zipCode) { | ||
this.zipCode = zipCode; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
serde-jackson/src/test/java/io/micronaut/serde/jackson/nested/NestedEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.micronaut.serde.jackson.nested; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
@Serdeable | ||
public class NestedEntity { | ||
|
||
@JsonUnwrapped(prefix = "hk_") | ||
private NestedEntityId hashKey; | ||
|
||
private String value; | ||
|
||
@JsonUnwrapped(prefix = "addr_") | ||
private Address address; | ||
|
||
@JsonUnwrapped | ||
private Audit audit = new Audit(); | ||
|
||
public NestedEntityId getHashKey() { | ||
return hashKey; | ||
} | ||
|
||
public void setHashKey(NestedEntityId hashKey) { | ||
this.hashKey = hashKey; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public Address getAddress() { | ||
return address; | ||
} | ||
|
||
public void setAddress(Address address) { | ||
this.address = address; | ||
} | ||
|
||
public Audit getAudit() { | ||
return audit; | ||
} | ||
|
||
public void setAudit(Audit audit) { | ||
this.audit = audit; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
serde-jackson/src/test/java/io/micronaut/serde/jackson/nested/NestedEntityId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.micronaut.serde.jackson.nested; | ||
|
||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
@Serdeable | ||
public class NestedEntityId { | ||
|
||
private Integer theInt; | ||
|
||
private String theString; | ||
|
||
public Integer getTheInt() { | ||
return theInt; | ||
} | ||
|
||
public void setTheInt(Integer theInt) { | ||
this.theInt = theInt; | ||
} | ||
|
||
public String getTheString() { | ||
return theString; | ||
} | ||
|
||
public void setTheString(String theString) { | ||
this.theString = theString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.