Skip to content

Tag: json

Jackson subtypes – how to specify a default

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 …

Adding default values to array in Jolt

I am trying to transform a json using jolt, it’s just adding some default values to an array. the input looks like this: The output should be: My spec looks right now: I just can’t pass the valC to the listWithItems and haven’t found anything in the documentation. Can someone help me with th…

How to read value from JSON with Jackson Java

I have a JSON file: I want to get the items separately. I try to do, but the result did null: This is class for Items: What I do wrong? how correctly read value from items? Answer You didn’t handle the JSON array – items – properly, so as I commented under OP, all what you need to do is

Convert nested map fields to snake case

how to convert all the nested fields of the following object rendered as json to snake_case? Given it’s read as a org.bson.Document, jackson object mapper won’t work as it’s designed for POJOs and it’s not possible to have POJOs here as the records are schema-less Answer It can be easi…

Processing a string formatted as a JSONArray

We have some code where we read a JSON file into a string and then use Json-lib to process it as follows: We now have a situation where the file is actually a JSONArray (i.e. starts with [ and ends with ]). The file passes all JSON validation tests but our code raises the following exception: We are able to