jackson

How do I log com.fasterxml.jackson errors with Quarkus?

走远了吗. 提交于 2021-02-05 09:27:43
问题 I use Jackson to check and databind input JSON for a REST API, and I would like to log the error when the input doesn’t match a @Valid constraint. However, the exceptions are throwned as a Response by the API but do not appear in Quarkus’ logs. How do I log Jackson’s exceptions ? 回答1: One has to create a handler for the Jackson exceptions, e.g. using ExceptionMapper. The following example catches all exceptions of type JsonProcessingException (finer tuning is obviously possible), logs them as

How do I log com.fasterxml.jackson errors with Quarkus?

Deadly 提交于 2021-02-05 09:27:11
问题 I use Jackson to check and databind input JSON for a REST API, and I would like to log the error when the input doesn’t match a @Valid constraint. However, the exceptions are throwned as a Response by the API but do not appear in Quarkus’ logs. How do I log Jackson’s exceptions ? 回答1: One has to create a handler for the Jackson exceptions, e.g. using ExceptionMapper. The following example catches all exceptions of type JsonProcessingException (finer tuning is obviously possible), logs them as

Deserializing a json which contains @JsonFormat(shape=JsonFormat.Shape.ARRAY) and custom object using jackson

六眼飞鱼酱① 提交于 2021-02-05 08:18:48
问题 I have a custom object : public class Response { @JsonProperty("values") private List<Value> values; @JsonFormat(shape=JsonFormat.Shape.ARRAY) public static class Value { public Value(long timestamp, float val) { this.timestamp = timestamp; this.val = val; } } } But when this is being parsed, I get "Can not deserialize instance of Response$Value out of START_ARRAY token". The json is : { "values":[[1552215648,18]] } Any idea if I'm missing something here? Or should I have a custom

Deserializing a json which contains @JsonFormat(shape=JsonFormat.Shape.ARRAY) and custom object using jackson

孤者浪人 提交于 2021-02-05 08:18:31
问题 I have a custom object : public class Response { @JsonProperty("values") private List<Value> values; @JsonFormat(shape=JsonFormat.Shape.ARRAY) public static class Value { public Value(long timestamp, float val) { this.timestamp = timestamp; this.val = val; } } } But when this is being parsed, I get "Can not deserialize instance of Response$Value out of START_ARRAY token". The json is : { "values":[[1552215648,18]] } Any idea if I'm missing something here? Or should I have a custom

Deserializing a json which contains @JsonFormat(shape=JsonFormat.Shape.ARRAY) and custom object using jackson

雨燕双飞 提交于 2021-02-05 08:18:06
问题 I have a custom object : public class Response { @JsonProperty("values") private List<Value> values; @JsonFormat(shape=JsonFormat.Shape.ARRAY) public static class Value { public Value(long timestamp, float val) { this.timestamp = timestamp; this.val = val; } } } But when this is being parsed, I get "Can not deserialize instance of Response$Value out of START_ARRAY token". The json is : { "values":[[1552215648,18]] } Any idea if I'm missing something here? Or should I have a custom

Recursive Nodes In XML Generated By JBPM 7

≯℡__Kan透↙ 提交于 2021-02-05 07:57:07
问题 The following XML is what JBPM spits out for variables used in a process. In other words, it is machine generated. I have tried for several hours to parse this with Jackson and has gone nowhere. Below you can find Java classes I am using. I am attaching a typical serializer that I have used with various debugging in eclipse without luck. XML: <map-type> <entries> <entry> <key>document</key> <value xsi:type="jaxbMap" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <entries> <entry> <key

Jackson also needs getter methods to correctly serialize a bean property using @JsonCreator

99封情书 提交于 2021-02-05 07:36:18
问题 I am using Jackson to serialize some beans into JSON, inside an application that is using Spring Boot 1.5. I noticed that to serialize a bean using the @JsonCreator correctly, I have to declare the getter method for each property, plus the @JsonProperty annotation. public class Person { private final String name; private final int age; @JsonCreator public Person(@JsonProperty("name") String name, @JsonProperty("age") int age) { this.name = name; this.age = age; } public String getName() {

Why doesn't this code work when wrapped in a generic function?

强颜欢笑 提交于 2021-02-05 06:59:26
问题 I use this code to perform a HTTP POST request and deserialize the returned value: ParameterizedTypeReference<MyClass> typeRef = new ParameterizedTypeReference<>() {}; HttpEntity<Object> requestEntity = new HttpEntity<>("some text"); ResponseEntity<MyClass> result = restTemplate.exchange("/test", HttpMethod.POST, requestEntity, typeRef); MyClass returnValue = result.getBody(); To make it easier to use, I tried to wrap the code in a function like so: public <T> T post(Object content, Class<T>

How to parse a json field that may be a string and may be an array with Jackson

微笑、不失礼 提交于 2021-02-05 06:49:05
问题 I have a json field that is string when there's one value: { "theField":"oneValue" } or array when there are multiple values: { "theField": [ "firstValue", "secondValue" ] } And then I have my java class that uses com.fasterxml.jackson.annotation.JsonCreator: public class TheClass { private final List<String> theField; @JsonCreator public TheClass(@JsonProperty("theField") List<String> theField) { this.theField = theField; } } The problem is that the code does not work when the incoming field

On demand lazy loading via dynamic @JsonIgnore annotation

与世无争的帅哥 提交于 2021-02-05 05:52:27
问题 I have something like: @Entity @Table(name = "myEntity") public class MyEntity { //.... @Column(name = "content") private byte[] content; //.... } PROBLEM : I pass MyEntity to the client as JSON string. But the problem is that I have two types of client's requests: I need to pass MyEntity with byte[] content array I need to pass MyEntity without byte[] content array In first case I needn't @JsonIgnore annotation, in second - do need. QUESTIONS : How to achive dynamical @JsonIgnore annotation?