I want to do something like this with subtypes. I have 3 different types of objects: value can either be a string or an object. The corresponding Java classes are I don’t mind having a discriminator inside Obj1 and Obj2, but there is no place for one when the value is just a string. Is there a way that …
Tag: jackson
Convert Java object to json string containing a json string property already
Consider a Java object like following: so when we do, I was expecting something like: instead I got it as a json value wrapped into a double quotes and skipped by backslashes as it was double jsonized – if this is actually a verb – Answer I managed to overcome this problem by using @JsonRawValue F…
Jackson throws error mapping exception when I try to deserialize a list of objects
I try to deserialize a huge API payload. This payload contains way more fields than I need and therefore I am utilizing @JsonIgnoreProperties(ignoreUnknown = true). However at some point the deserialization fails with the error message: I found solutions for that case that suggested the use of I tried this. B…
Deserialize empty JSON array into empty TreeMap
I’m new to Java, and I’m wondering how to deserialize an empty JSON array into an empty Java object of type TreeMap<String, MyOtherClass>. Currently, I’m attempting to deserialize a JSON file with an array of objects, and each object into a class called MyClass. The class is roughly as…
Ktorm entities as springboot controller parameters
I’m trying to use Ktorm in my new springboot application, and get myself into problem when trying to use Ktorm entities interfaces as springboot controller parameters. The entity and Controller look like this: I got this exception once calling function addTask(): [HttpMessageConversionException] Type de…
Serialize Enum as String for validation using Jackson
I’m trying to validate an Enum using the custom validator, in my custom validator I’m trying to return a custom message when a parameter does not exist in the enum values. Bellow my enum Bellow my PostMapping method I can’t switch the type of enum to string in the method itself because IR…
Jackson serializes Enum to NAME not value (XML) Java
I have this Enum defined: I have a model object that has a OutputFormatEnum variable called OutputFormat. When I set this variable to OutputFormatEnum.PDF, it is initially registered as “pdf” which is what it should be. When I then execute the following code: It sets the value of OutputFormat in s…
How to deserialize json to nested custom map via gson?
I have the following json To deserialize it, I have the following data model class. I am not getting any deserialization error when I am using gson but the profiles variable is coming as null. This is how I am deserializing. var json = gson.fromJson(data,json.class) inside the match object there can be a dyna…
Jackson deserialise JSON with many dynamic nodes
I’m trying to deserialize a JSON file with the format of But I don’t want to create a class for each language (thousands) so I wrote a custom LanguageDeserializer which gives me back the List<Language> that I want I have a parent class to wrap the results: So when I try and use it The langua…
How to convert an input into a method that the program will understand
I’m currently working on my homework about client and server topic: I created a class called VehileRequest.java which will take three variables (year, make, model) from Client.java and pass them to Server.java then the Server will get information from VehicleRespone.java and display the information abou…