jackson2

parse recursive nested field using jackson

六眼飞鱼酱① 提交于 2019-12-17 21:18:57
问题 I have a below JSON and from which I need to make a Map<String, String> . In the below JSON, I have only three levels of parentCategory but in general it can be more or sometimes it can be less. Key of my map will be 79720 which is id of categories section and value should be 10987 which is id of last parentCategory . Now I can have nested parentCategory inside them so I am having issues making a POJO for this. I can have one level parentCategory or I can have nested parentCategory inside

Jackson JsonNode Serialization

有些话、适合烂在心里 提交于 2019-12-13 07:28:44
问题 I'm using AWS Lambda with a Java 8 function. Lambda has a builtin Jackson Serializer so when your method returns an object it serializes it to a JSON representation. I have an onject that is made up of the following properties: private String name; private JsonNode model; private JsonNode field; I've omitted all the rest of the class for simplicity but it has getters / setters etc. Normally when I run this in my native application it works perfectly. The JsonNode Tree structure is rendered as

Java Jackson Serialization ignore specific nested properties with Annotations

安稳与你 提交于 2019-12-11 19:03:21
问题 I'm using jackson (with spring boot) to return some DTOs like json. The problem is that I have specific DTO which contains nested objects, which contains another objects. Can I have ignore some nested properties directly from the DTO, without any Annottations on the nested objects (because they are used in another DTOs) public class MyDTO { private MyObjectA a; } public class MyObjectA a { private MyNestedObject b; } I want when i serialize MyDTO to exclude MyNestedObject b I've tried with

Jackson registerSubtypes not working in Kotlin

橙三吉。 提交于 2019-12-11 07:55:01
问题 I was trying to use the registerSubtypes function from Jackson following this tutorial. So I've converted this code into Kotlin like so: interface Vehicle { val name: String } class Car @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle class Truck @JsonCreator constructor(@JsonProperty("name") override val name: String) : Vehicle class Vehicles @JsonCreator constructor(@JsonProperty("vehicles") var vehicles: List<Vehicle>) fun main() { val MAPPER =

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

Jackson configuration to consume list of records in rabbitmq

 ̄綄美尐妖づ 提交于 2019-12-11 02:27:19
问题 I am using spring boot amqp in which I will be consuming a list of Employee objects from a queue. My listener method looks like this: @RabbitListener(queues = "emp_queue") public void processAndPortEmployeeData(List<Employee> empList) { empList.forEach(emp -> { some logic }) } However, when I try to consume the message, I get a class cast exception: For some reason, I'm getting a LinkedHashMap. Caused by: java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.integration

jackson kotlin - Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token

半城伤御伤魂 提交于 2019-12-11 01:07:39
问题 I am getting a json string from Fitbit API. I want to save dateTime and value fields in a List object. I´m using jackson module kotlin. I have created ActivitiesSteps data class for this. I don´t know how to avoid "activities-steps" field and I´m getting stucked. This is the JSON body(provided in variable 'jsonSteps' to readValue method in my code below): { "activities-steps":[ { "dateTime":"2018-04-17", "value":"11045" }, { "dateTime":"2018-04-18", "value":"14324" }, { "dateTime":"2018-05-16

Force Milliseconds When Serializing Instant to ISO8601 using Jackson

依然范特西╮ 提交于 2019-12-10 02:12:23
问题 I have some questions related to JSON serialization using Jackson in a project where I use Spring Boot 2.0.0.M6 , Spring Framework 5.0.1.RELEASE and Jackson 2.9.2 . I have configured the following Jackson-related settings in application.properties : spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false Serialization works mostly as I need. Nevertheless, I have noticed that Jackson seems to cut-off milliseconds if they are 000 . Test 1: Serialize Instant with milliseconds set to 000 :

Weblogic 12.2.1.3 from Moxy to Jackson

落爺英雄遲暮 提交于 2019-12-08 08:16:39
问题 I would like to change the JSON parser from Moxy to Jackson, and I have followed the shared library approach, but without any result, Moxy is still used. Note: the shared library is not necessary!!! The shared library I have created a maven project with the following dependencies and descriptors. pom.xml <properties> <jackson.annotations.release>2.8.6</jackson.annotations.release> <jersey.version>2.22.4</jersey.version> </properties> <dependencies> <dependency> <groupId>com.fasterxml.jackson