jackson-databind

How to customly serialize or convert a Map property with custom key type in Jackson JSON (de-)serialization?

故事扮演 提交于 2019-12-11 08:38:43
问题 I'm serializing instances of @JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope=Entity1.class) public class Entity1 { private Long id; @JsonSerialize(converter = ValueMapListConverter.class) @JsonDeserialize(converter = ValueMapMapConverter.class) private Map<Entity2, Integer> valueMap = new HashMap<>(); public Entity1() { } public Entity1(Long id) { this.id = id; } [getter and setter] } and @JsonIdentityInfo( generator = ObjectIdGenerators

Jackson Deserialization Fails because of non-default constructor created by lombok

岁酱吖の 提交于 2019-12-11 07:28:30
问题 Jackson can deserialize json for the following class in 2.6.5 but fails in 2.8.8. Model: public static class Parent { public long id; public List<Child> children; } @RequiredArgsConstructor public static class Child { public long childId; @NonNull @JsonIgnore public Parent parent; public Child() { } } JSON: { "id": 1, "children": [ { "childId": 2 } ] } The exception is: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "childId" (class Parent), not marked as

Bypass runtime type erasure for generic map serializer

﹥>﹥吖頭↗ 提交于 2019-12-11 06:05:24
问题 I'm working on a serializer for a Map<K,V> which serializes map entries as JSON array of objects with key and value being able to contain arbitrary types (including complex types for keys). I have public class MapEntryDeserializer<K,V> extends StdDeserializer<Map<K,V>> { private static final long serialVersionUID = 1L; public MapEntryDeserializer(Class<Map<K,V>> vc) { super(vc); } public MapEntryDeserializer(JavaType valueType) { super(valueType); } @Override public Map<K, V> deserialize

How to modify the value of a JsonNode recursively using Jackson

坚强是说给别人听的谎言 提交于 2019-12-11 05:07:09
问题 Requirements: I want to apply some functions on the inner values of the JsonNode . The functions can be different eg:- lowercasing some values or appending something to the values or replace the values with something. How can I achieve that using Jackson library? Note that the structure of the JSON data can be different which means I want to build a generic system which will accept some path expression which will basically decide where to change. I want to use functional programming style, so

how to deserialize one to many relationship with both eager sides without ending up in infinite deserialization loop

我与影子孤独终老i 提交于 2019-12-11 01:09:20
问题 here is my Product class @Entity public class Product { @ManyToOne(fetch=FetchType.EAGER) @JoinColumn(name="listingGroup_id") @JsonBackReference public ListingGroup listingGroup; and here is my groupProduct class @Entity public class GroupProduct { @OneToMany(mappedBy = "listingGroup", fetch = FetchType.EAGER) @JsonManagedReference Set<Product> products; GAOL : When I query for product, I want product with ProductGroup (ProductGroup should not serialize again the products inside) When I query

How do I unwrap a list of list wrapped items in Jackson?

此生再无相见时 提交于 2019-12-10 15:59:12
问题 I have a bean that resembles this: public class Product { public String id; public String vendor; public Set<Image> images; } public class Image { public String originalSrc; } I'm trying to deserialize my JSON that resembles this: { "id": "gid:\/\/mysite\/Product\/1853361520730", "vendor": "gadgetdown", "images": { "edges": [ { "node": { "originalSrc": "https:\/\/cdn.something.com" } }, { "node": { "originalSrc": "https:\/\/cdn.something.com" } } ] } I'm unable to deserialize the object as

Immutable Lombok annotated class with Jackson

爷,独闯天下 提交于 2019-12-09 14:31:00
问题 What is the preferred way to create class that is Immutable Can be serialized/deserialized with Jackson Human-readable and with low level of boilerplate Preferably, I would have liked something like this to work: @Data(onConstructor = @__(@JsonCreator)) and then have all fields to be private final . However, this does not even compile (and I'm not sure why). Using @AllArgsConstructor(onConstructor = @__(@JsonCreator)) will compile but only yields InvalidDefinitionException: No serializer

SimpleDateFormat with Timezone set gets correct value but wrong zone

烈酒焚心 提交于 2019-12-07 08:04:10
问题 I have a simple test in a Spring application, which has default timezone set to UTC : @SpringBootApplication public class MemberIntegrationApp { @Autowired private TimeZoneProperties timeZoneProperties; @PostConstruct void started() { TimeZone.setDefault(TimeZone.getTimeZone(timeZoneProperties.getAppDefault())); // which is UTC } public static void main(String[] args) { SpringApplication.run(MemberIntegrationApp.class, args); } } And, this simple test: ( The test class is annotated with

Jackson deserialize based on property name

强颜欢笑 提交于 2019-12-06 03:36:05
I have the following two types of JSON objects: {"foo": "String value"} and {"bar": "String value"} Both of them represent a specialized type of the same base object. How can I use Jackson for deserializing them ? The type information is only represented by the keys themselves and not the value for any key (almost all examples use the value of the key for determining the type : https://github.com/FasterXML/jackson-docs/wiki/JacksonPolymorphicDeserialization ) Jackson doesn't offer an out of the box solution for that, but it doesn't mean that you are out of luck. Assuming that your classes

Immutable Lombok annotated class with Jackson

▼魔方 西西 提交于 2019-12-04 00:59:17
What is the preferred way to create class that is Immutable Can be serialized/deserialized with Jackson Human-readable and with low level of boilerplate Preferably, I would have liked something like this to work: @Data(onConstructor = @__(@JsonCreator)) and then have all fields to be private final . However, this does not even compile (and I'm not sure why). Using @AllArgsConstructor(onConstructor = @__(@JsonCreator)) will compile but only yields InvalidDefinitionException: No serializer found for class Another alternative which: meets the criteria has less boilerplace than the current top