Questions tagged [jackson]

Jackson is a Java library for handling tasks like reading and writing (parsing / generating) and data binding to/from Java objects. Although primarily used for JSON, Jackson also supports many other data formats such as Avro, CBOR, CSV, Java Properties, Protobuf, Smile, XML and YAML.

0
votes
0answers
14 views

How to parse Input Object Date fields with format given in the object field itself

I have a Spring project where in the controller method I am having '@RequestBody Object obj' as one of the parameter. Object have Date fields which are having custom JSON Serializer and custom JSON ...
0
votes
0answers
15 views

Jackson fails to recognize @class type identifier in JSON payload

I have an hierarchy of Java POJOS, the base class being abstract. To ensure Jackson can deserialize from JSON into the correct concrete types I have annotated the base class with @JsonTypeInfo(use=...
0
votes
0answers
9 views

Error saving parent-child entity with JpaRepository

I have a parent-child entity set up like this. The AuditEntity simply sets up some common fields for audit purposes (stuff like dateCreated, dateUpdated etc). Parent @Entity @Table(name = "...
0
votes
2answers
29 views

Jackson ObjectMapper deserialize Map with Json string key

The task is create correct Json string representation. There are Map that may contains value that Json string. During write this map to string mapper escape new line and quote Json. private String ...
2
votes
1answer
22 views

ObjectMapper has to call Constructor with Arguments not provided by JSON file

My goal is to write some kind of bridge between our global event broker and Spring's ApplicationEvent system. The message broker provides the messages in JSON format. My idea is to have an public ...
1
vote
1answer
21 views

Retain type information while jackson serialisation and unserialize accordingly

I am stuck in a use case where I have an Object of Class A lets say a, and an Object of class B lets say b, b intern has a member variable of a subclass of Class C lets say c. My use case is that I ...
0
votes
0answers
6 views

How to perform condition serialization using Jackson, based on user permissions on the object?

Lets consider a Spring MVC api where a controller has 2 endpoints. The first endpoint returns Employee and the second Department. For the sake of simplicity the entities look like: public class ...
0
votes
0answers
13 views

Can I create one custom Jackson deserializer to handle all JSON scalar types? [duplicate]

I can create class StringJsonDeserializer extends JsonDeserializer<String>, class IntegerJsonDeserializer extends JsonDeserializer<Integer>, and so on. However, I would like to avoid ...
2
votes
3answers
50 views

how to convert json into pojo where no param name is given

I am trying to convert JSON to java using Jackson. But not getting proper solution. I have JSON which does not have parameter name in it. I want to use PropertyOrder to map json fields to POJO. I ...
0
votes
0answers
27 views

Is it how to set up an ObjectMapper dynamically at the time of user session creation?

Currently in my project, the ObjectMapper is set to the spring XML, but I would like some settings in this ObjectMapper to be different, depending on the logged-in user. It is possible?
1
vote
0answers
25 views

Fixing Swagger-Ui's JSON-example - Show JsonNumber instead of Object

In our Java/Spring project we use Swagger-Ui for automatically documenting our REST-APIs. Lately I went on to try to ensure proper documentation for all our APIs and found, that for some endpoints the ...
0
votes
0answers
32 views

ObjectMapper not handling double quotes correctly

I am trying to implement a HTTP Patch request into Postgres JSONB. The input of the request is a patch request in json, I map this object to a auto generated POJO based on a open API Spec using ...
1
vote
1answer
70 views

How to use JacksonJSONProvider ObjectMapper() class in Java?

I want to deserialize the OffsetDateTime JSON object into ISO8601 format I have generated the JacksonJSONProvider classes through swagger-code-gen but I am not able to figure out how to use class... ...
0
votes
1answer
20 views

how to map a request object data that can have different types and extends from another class?

Hello everyone and thanks for the help. lets say I have: @PUT @Produces(MediaType.APPLICATION_JSON) @Path("/endpoint") public A createA(A a); Model A: @JsonTypeInfo( use = JsonTypeInfo.Id....
0
votes
0answers
35 views

Jackson FasterXML transforming to POJO with namespaces

I want to use FasterXML to transform an xml into a java object, transform it back to an xml and produce the exact same output with namespaces Here is the original XML: <customer xmlns:xsi="http:...
0
votes
0answers
24 views

Getting MismatchedInputException instead of MissingKotlinParameterException

I want to deserialize simple json to TestEntity: data class TestEntity ( val id: Long, val objType: String? ) And here is a json where id property is missing intentionally: val json = """{ ...
0
votes
1answer
22 views

Hibernate Validator doesn't validate method parameters annotated with constraint annotations

I have a pojo, which is common for multiple services and each of them has different validation rules for that object. So, I am extending that pojo in each of my services and override some of the ...
0
votes
0answers
17 views

Deserialize and serialize JSON only to restructure it?

I want to restructure a JSON file. The way I am thinking is to deserialize and serialize back to JSON object using jackson and jsonPath. I will explain with an example: file1.json { v1: foo, ...
-1
votes
1answer
19 views

How to auto scale of Java War Deployment Setup

I have a Java Tomcat War Deployment Setup on AWS EC2 Ubuntu Linux Machine. And this server is based on some APIs and some computation. Now, it is consuming 15% to 20% Server CPU Utilization. And ...
1
vote
1answer
26 views

Error while mapping xml to java using jackson: com.fasterxml.jackson.databind.exc.MismatchedInputException

I have an xml file that I have to parse and map to a Java class: <udm.DeployedApplication id="ID" token="TOKEN" created-by="AUTHOR" created-at="2018-12-10T10:02:36.264+0000" last-modified-by="...
0
votes
0answers
20 views

How to make Jackson take @JsonView into account when serializing ANY response in Spring Boot app?

I want to implement the following functionality: when serializing my dto model in the response from a controller method, it usually should be returned without a couple of fields (e.g. name field), but ...
1
vote
0answers
19 views

Lombok's lombok.copyableAnnotations not working with Jackson annotations

I'm trying to make use of Lombok's new copyableAnnotations feature in order to have Jackson annotations like @JsonIgnore and @JsonValue copied to generated getter/wither methods. This blog seems to ...
0
votes
0answers
32 views

No description found for classes with custom Jackson ObjectMapper

I am coming across an issue with Spring AutoRest Docs. It seems to stem from this code .alwaysDo<DefaultMockMvcBuilder>(JacksonResultHandlers.prepareJackson(objectMapper)) Full configuration: ...
0
votes
1answer
28 views

XML mapping with Jackson no String-argument constructor/factory method to deserialize from String value ('Belgian Waffles')

for learning purposes I am trying to map xml file to pojo. My xml looks like this: <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</...
0
votes
1answer
12 views

Spring jackons serialise list [closed]

I have a spring boot project, and im trying to serialize an object that contains a list into Json, When i test it using a mapper instance to inspect the json. i get the following output: {"genuine":["...
0
votes
1answer
22 views

Error while deserializing Map<IgnoredCaseKey, Object> response from spring restTemplate

while calling API request from a service I get the following error: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang....
0
votes
0answers
22 views

Spring Boot with OAuth2RestTemplate and GZIP compression

I have a spring boot server that communicates with a REST service. This service is secured by Keycloak. The response of the REST service is compressed by gzip. Now I get following error for a request: ...
0
votes
0answers
16 views

How to escape special characters in swagger schema example values?

In swagger (3.0) definition yaml, if I have a schema with a string property and add a custom example value, special characters like <,>,& appaers on browse "wrong". eg.: < -> < I tried ...
0
votes
0answers
24 views

How to configure Jackson to serialize/deserialize a RFC3339 datetime [duplicate]

I have a timestamp, which I was told is a timestamp without a timezone according to RFC3339: 2007-12-01T10:00:10Z But my research says that this particular timestamp has a UTC timezone called '...
0
votes
1answer
18 views

Kotlin inheritance: Objects are not equal after serialization and deserialization to / from json

I have kotlin classes with inheritance: abstract class Classification( val accuracy: Double ) @Document class OrderForm( @Id val id: String, accuracy: Double, ...
0
votes
3answers
67 views

Is there a way to serialise Java TreeMap into a JSON?

I have a Java TreeMap frutitas inside a custom object on the server side which I want to send to the frontend. I use javax.ws and jackson to serialise. The data that I get in the frontend looks like ...
0
votes
1answer
25 views

Manually constructing node tree: how do I rename <ObjectNode> tags

I'm trying to set up code to create a node tree using jackson which can then be used to write either JSON or XML. I've created the node tree manually like so: XmlMapper NodeMap = new XmlMapper(); ...
0
votes
0answers
8 views

jackson - exlude a single property from all serializations, except when a View is used

i am using Springs @RestController and have a problem with some Jackson-mappings. I will try to explain as simple as possible: i have a class A with 5 fields (v, w x, y, z) and what i basically want ...
0
votes
1answer
43 views

How do I skip serialization of specific fields for specific values in jackson?

So I have class Foo { double bar = -30000.0 double baz = 200 } -30000.0 is not actually a valid value, it's the default value emitted by the hardware, realistically this should be a null value. ...
0
votes
2answers
90 views
+50

How to make Jackson to inject the Generic Class into a bean?

Lets suppose, that we have a bean like this: public class Response<T> { private T data; private double executionDuration; private boolean success; private String version; //...
0
votes
1answer
26 views

How to serialize and deserialize a list of objects using Jackson

I am getting an error while deserializing an array of objects. ans int the below expression is a List<Restaurant> type String json = obj.writeValueAsString(ans); I am getting error in the ...
0
votes
0answers
12 views

Jackson serialization for single object or array

Is there a way to load a single Json object into a POJO class and a Json array into a Groovy list in a single statement like this? JsonUtil.loadObjectFromJson(expectedResultsFile, new TypeReference ...
0
votes
1answer
47 views

Can not deserialize instance of java.lang.Boolean out of START_ARRAY token

I need to handle the return of a call, however it can return a Boolean or a object. When the phone number is found, it crash right into onFailure. I'm looking for solutions but all found did not ...
1
vote
0answers
32 views

Is there a way to read a json file with jackson and create other objects than the one given in readValue()

In short I want to simplify my code. Right now I store a 2-dimensional array of int's in a json file. This is already read correctly and converted to an 2-dimensional Sprite array. But the problem is ...
0
votes
2answers
26 views

Jackson Mixin not working in Pojo to json

My target is xml to Pojo and Pojo to json. I already did xml to pojo using jaxb. Now I am trying pojo to json using jackson Jaxb. Where I am getting the following json which produce JXBElement class ...
0
votes
0answers
17 views

Generate @NotNull from api.yml using Swagger CodeGen task in build.gradle

Not able to generate @NotNull annotations to the Fields/properties. Instead it is getting generated on a getter method. This is causing a problem of null values can be set to the generated POJO. Is ...
3
votes
3answers
56 views

custom deserializing a date with format

["last_modified"])] with root cause java.time.format.DateTimeParseException: Text '2018-06-06T13:19:53+00:00' could not be parsed, unparsed text found at index 19 The inbound format is 2018-06-...
0
votes
1answer
22 views

Jackson custom deserializer null codec

I have wrote custom deserializer for my type, which is represented as interface Attachment and there are two implementions of this interface Photo and Video. When parsing I recognize them from json ...
1
vote
1answer
40 views

How to parse inner json string as nested class using retrofit

I have used retrofit with nested classes before, but the current api I'm tring to use has such a structure: Request body: { "Id" : "a2", "messageCode" : 1, "bigNestedClass" : "{\"field1\":...
0
votes
0answers
40 views

How to parse a Json with a field containg several kind of objects

How to parse a Json with a field "data" which can contain several types of objets, or an object and a simple message (outside the object structure). An Android app request information to its backend. ...
0
votes
0answers
33 views

Java Class to JSON custom Schema by Annotation

I am currently generating my Json Schema like this: class Item { public int id; public string name; public string description; } ObjectMapper mapper = new ObjectMapper(); ...
0
votes
1answer
29 views

JSON jackson reading Class values of hashmaps as LinkedHashMap

I'm saving a score (KillcountRatio class) to a name (String) in a HashMap that I am saving with Jackson JSON, but when loading the saved json file, it is unable to cast the KillCountRatio class value ...
0
votes
0answers
21 views

Generate Java classes from YML or YML Schema through maven using a plugin

Is there any way to generate java classes from yml when running mvn clean install? Its do able in xml and json, but i am not able to find any in yml. I tried for xml and json,and its working fine for ...
0
votes
3answers
58 views

How to read JSON array from HttpServletRequest?

I am very new to servlet and I am unable to read JSON array from HttpServletRequest I am sending below JSON to Java page: 1 start: 0 limit: 20 sort: [{"property":"fiscalYear","direction":"DESC"}] ...
0
votes
2answers
57 views

Why isn't JSON being unmarshalled into my Java class?

I'm using Spring Boot and RestTemplate to GET data from an in-house service. The JSON I'm getting back as the response isn't being unmarshalled into my object and I'm unable to figure out why. (I'm ...