1,182 questions
0
votes
0
answers
59
views
Serializing generic Object properties to Avro union types
I am trying to map a generic Java object client RequestDto to a complex Avro record that includes unions.
The Situation:
I have been given an Avro schema, which means I can't/shouldn't make any ...
0
votes
1
answer
81
views
Is it possible create an ObjectMapper configured such that it AES encrypts all fields except fields annotated with a certain annotation?
Let's say you have an annotation configured on a per field basis:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import ...
0
votes
0
answers
52
views
Is it possible have Jackson's ObjectMapper honor the configured serialization features when serializing a JsonNode?
ObjectMapper mapper = new ObjectMapper()
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
Map<String,...
-1
votes
1
answer
168
views
Getting JSON from URL (from API that need an authentication token) SPRING
I am trying to build database - and i want to get data that i need from API which have an authentication token - im using Java, Spring, MySql DB
I've created simple example of what i want to achieve - ...
0
votes
2
answers
168
views
How to override @JsonProperty(value = "id", access = JsonProperty.Access.READ_ONLY) on object mapper
I've a model class which I can't change its source, it is annotated with
public class Announce {
@JsonProperty(value = "id", access = JsonProperty.Access.READ_ONLY)
@Id
@...
0
votes
1
answer
165
views
How to configure PersistentEntityJackson2Module in Spring Boot 3.4.0?
We are migrating the Spring Boot application (mixture of Spring Data Rest with plain vanilla mvc) from version 2.5.12 to 3.4.0. The application heavily depends on the ObjectMapper configured with ...
4
votes
1
answer
4k
views
java.lang.NoSuchMethodError: 'void com.fasterxml.jackson.core.util.BufferRecycler.releaseToPool()'
I've upgraded Jackson from 2.16.1 to 2.18.2 in my build.gradle:
plugins {
id 'java'
id 'jacoco'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id "org.sonarqube" ...
0
votes
0
answers
107
views
ObjectMapper truncates strings in Map
I'm trying to parse a JSON string into a Map using ObjectMapper. To achieve this, I used this simple code below.
ObjectMapper objectMapper = new ObjectMapper();
Map value = objectMapper.readValue((...
2
votes
1
answer
63
views
Derive TypeReference for wrapper type from nested type
Jackson's TypeReference allows reifying the generic type parameters of a type via subclassing. Example:
final var typeRef = new TypeReference<List<MyType<MyArg>>>() {};
final List<...
0
votes
1
answer
105
views
Jackson: Deserialize all kind of non-existing Lists into empty Lists [duplicate]
Given the following SampleTestClass where I try to parse JSON to Java:
class EmptyListDeserializerTest {
final ObjectMapper objectMapper = new ObjectMapper();
{
objectMapper.configOverride(List....
0
votes
2
answers
11k
views
JsonParseException while parsing double quotes in Java string using object mapper
I have an issue while trying to parse a string value using object mapper.
Below is my code,
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Payload {
private String id;
private ...
-1
votes
1
answer
73
views
Jackson Custom Object Mapper [closed]
I'm looking for some help. I have a requirement to convert the input json to a java object.
Input JSON is something like this
{
"code" : "some code",
"type" : "...
0
votes
2
answers
253
views
Spring controller won't deserialize instant
I'm having trouble integrating Spring with Jackson.
I have a POJO which has some Instant fields with a custom date format:
public class C{
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = &...
0
votes
1
answer
622
views
ObjectMapper in RestClient not picking up configuration properties
In my Spring Boot service, I'm using RestClient to perform REST calls. I want to ignore null values in request bodies so I set up
spring:
jackson:
default-property-inclusion: "non_null"...
1
vote
1
answer
91
views
Jackson Object Mapper readTree with boolean values
{
"data":{
"id":"550e8400-e29b-41d4-a716-446655440000",
"timestamp":"2023-05-01T16:34:16.993007076Z",
"isProcessed":...
1
vote
0
answers
73
views
Byte array passthrough via Jackson ObjectMapper
I have a java openapi generated client which I use to retrieve some image from a remote server (this process runs fine against a browser, postman, etc.). I am able to configure the objectMapper of the ...
1
vote
1
answer
568
views
How to force XmlMapper to retain the root element?
I have the following minimal code:
final var xmlString = "<parent><child>data</child></parent>";
final var xmlMapper = XmlMapper.xmlBuilder()
.enable(...
4
votes
1
answer
156
views
How to get Java 8 time classes to work on Jersey Jax-RS clients?
You can tell how to configure ObjectMapper to automatically handle LocalDateTime class covered here:
serialize/deserialize java 8 java.time with Jackson JSON mapper
But when I try to use POJOs with ...
1
vote
1
answer
195
views
RedisJSON vs Jackson ObjectMapper
There are two ways to handle JSON in Redis:
Use Jackson ObjectMapper to serialize the data before storing it in Redis, and then deserialize it when retrieving the data.
Use the RedisJSON module to ...
0
votes
1
answer
112
views
ObjectMapper - YAML parse - ignore comments
YAML file example
---
# Author : John Doe
# Updated Date: 6/21/2024 4:23:22 PM
# Status: Deployed.
name: "stack overflow"
version: 5
While parsing the yaml file, How to ignore the comment ...
2
votes
1
answer
191
views
Jackson's JsonSerializer don't work for deep-nested object hirarchies
For the serialization of Java object instances I use the Jackson Library and have built several JsonSerializers, which should individually check Player.class, Vehicle.class and Building.class and ...
1
vote
0
answers
146
views
Solve conflicting getter definitions for property in Jackson
I have the following class:
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import ...
0
votes
1
answer
74
views
How print Date as Date using ObjectMapper in Spring App?
I am using Spring XML App (not Spring Boot and can't move), when I used below code I am getting details value for Date, what I want to just print yyyy-MM-dd format.
import com.fasterxml.jackson.core....
0
votes
1
answer
199
views
Object Mapper readValue function returns Null in Spring Boot 3
Below is my response POJO Class
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ProductResponse {
boolean required;
ProductModel model;
}
Below is my code where I'...
3
votes
1
answer
157
views
How to censor custom annotated fields in java dtos?
I need a handy way to censore DTO fields/secrets when converting them into a json string (for logging).
Im using objectmapper and I heard about @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) ...
0
votes
2
answers
163
views
Java Jackson update json 2nd value instance in array
Hey all I am trying to figure out how to go about updating a part of my json. So far I have not found anywhere that shows me how to do this.
For an example, this is what I am needing to update:
{
&...
1
vote
1
answer
503
views
Java 8 date/time type not supported by default - when using RestEasy client POST request
I am using RestEasy client POST request as in the following interface:
@POST
@Path("/somePath")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
Response ...
1
vote
0
answers
18
views
The JSON returned by springboot contains the class path of the return class
I use springboot2.7.18 to get a JSON
This is my objectMapper config file.
@Configuration
public class JackJsonConfig {
@Value("${spring.jackson.local-date-time-format}")
String ...
0
votes
1
answer
48
views
Java - Parse enum from api by text description
I have a lib which i cannot change.
This lib has api method which returns json like this {OrderStatus=PartiallyFilledCanceled}
and also this lib has a enum
@AllArgsConstructor
public enum OrderStatus {...
0
votes
1
answer
66
views
JSON string wrapping within another JSON object
Below is my SMS class
public class SMS implements Notification {
private static final Logger LOG = LogManager.getLogger(SMS.class);
private static final Properties PROP = PropertyReader....
-1
votes
1
answer
236
views
getting "NULL" instead of null in Json response in java
I have my own object when there is no value it is coming as "NULL" in a string from downstream and it is failing while converting to java object in ObjectMapper
class Test
private String ...
0
votes
2
answers
429
views
Jackson ignore customized ObjectMapper in API response of Quarkus app
I have the Qurakus app with REST API
@Path("/hello")
public class ExampleResource {
@GET
@Consumes(MediaType.APPLICATION_JSON)
public ObjectNode hello() throws ...
0
votes
1
answer
240
views
When deserializing a map with Long keys from JSON using an jackson objectmapper, the Long keys are being deserialized as Strings
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com....
-1
votes
1
answer
80
views
How to unwrap nested json object as an entity
I am calling another api and get the below json response
{
"metadata": {},
"data": {
"productId": 102001,
"productName": "P101"...
1
vote
0
answers
203
views
Exclude empty Arrays and values from Jackson XmlMapper
I am trying to form an Xml from a json. I have Object templates for json and using ObjectMapper to map. While i transfrom, there are some aspects that i need to follow for required rules. If an array ...
-1
votes
1
answer
142
views
Different Output for Test Between IntelliJ and Maven?
I have a simple check with ObjectMapper.writeValueAsString for a test to verify that no input have been changed without a developer having noticed it. It works fine but the issue is that the length ...
1
vote
1
answer
106
views
Jackson JsonNode to Typed Collection: Should ObjectReader for TypedReference be Singleton?
When converting a Jackson JsonNode to a Java collection?
See question/answer below: https://stackoverflow.com/a/39237947/15435022
ObjectMapper mapper = new ObjectMapper(); // singleton in the project
...
0
votes
1
answer
3k
views
Do you know pretty way to log you objects in json format?
When use spring boot, from time to time I need to log my objects like UserInfo, Person and another to log in json format
If I log just to put my object, logs looks like User@3242 (with hash code)
So I ...
0
votes
0
answers
216
views
Cannot deserialize value of type java.lang.String from Object value
I have Big JSON payload and I am trying parse this Json into Target class. in the target class there is one filed which is String type. But JSON payload will have Object structure. When I parse this ...
1
vote
0
answers
57
views
Not clear how to inject custom ObjectMapper for @SpringBootTest(SomeController.class)
Affects: \3.1.5
I am using custom configuration for an ObjectMapper like that:
@Autowired
private ObjectMapper objectMapper;
@Override
public void extendMessageConverters (List<...
1
vote
1
answer
2k
views
error attempting to convert the JSON string response from the API to a Map<String, Object>
I am encountering an issue while consuming an API that returns a JSON string. When attempting to convert the JSON string response from the API to a Map<String, Object>, it throws an error. ...
-2
votes
1
answer
2k
views
NullPointerException: Cannot invoke "com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(Object)" because "this.objectMapper" is null [duplicate]
My unit test is getting the error "this.objectMapper" is null"... I have marked the objectMapper with @Autowired annotation.
java.lang.NullPointerException: Cannot invoke "com....
1
vote
0
answers
67
views
Jackson : default typing for main/container type only
I would like to ask if there is any option to turn on default typing for main, "containter" class only?
I have a simple, testing class "Document" which is my container type for ...
0
votes
1
answer
285
views
Jackson ObjectMapper - How to configure to not use a custom Json Serializer
I am working on a project which has a custom JSON Serializer defined
public class JsonCustomSerializer extends JsonSerializer<CustomObject> {
@Override
public void serialize(
...
2
votes
1
answer
625
views
Deserialise the JSON into custom object enclosed in optional
I have 2 classes as such
class Parent {
private final Optional<Child> child;
@JsonCreator
Parent(@JsonProperty("child") Optional<Child> child) {
this.child =...
0
votes
1
answer
57
views
Spark Dataframe Vs traditional object mapper
Traditional object mapper is used to abstract the code and the database in typical use cases. In my scenario, I am using spark to read data from source and converting to dataframe. The target for my ...
-1
votes
1
answer
36
views
Java object to JSON conversion is giving extra attributes which is not present in java builder class
I am working on Java Object to JSON conversion using ObjectMapper but it is giving extra attribute which is not present in my java class.
Below is the Java Object Builder class.
@JsonDeserialize(...
0
votes
1
answer
57
views
Check type of Json property's value on converting to Java class
Let's say I have the following Json data, here I have the id of type integer, and in Java class the type of id is String.
{
"id": 1,
"name": "user1"
}
@lombok.Data
@...
0
votes
2
answers
838
views
Is there an existing Quarkus function to deserialise a CloudEvent from a JSON String?
I am currently working with Quarkus, and I encountered an issue while wanting to deserialise a JSON String message recieved through a WebSocket to a CloudEvent.
Using the Quarkus ObjectMapper doesn't ...
0
votes
1
answer
102
views
How to unmarshall a string constant object from JSON to as a Java Object?
I have the following JSON:
{
"code":1000,
"message":"Success",
"data":{
"results":[
{
"lineId":"...