In your case, I would write a custom JsonDeserializer. Haven't really tested the code, but I think the idea is clear:

    final MyClassDeserializer myClassDeserializer = new MyClassDeserializer();
    final SimpleModule deserializerModule = new SimpleModule();
    deserializerModule.addDeserializer(MyClass.class, myClassDeserializer);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(deserializerModule);

And the code for JsonDeserializer:

    public class MyClassDeserializer extends JsonDeserializer<MyClass> {

    @Override
    public MyClass deserialize(final JsonParser jsonParser, final DeserializationContext context)
            throws IOException {
        final JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        final JsonNode sourcesNode = node.get("sources");
        if(node.isArray()) {
            final ArrayNode arrayNode = (ArrayNode) node;
            final Iterable<JsonNode> nodes = arrayNode::elements;
            final Set<Source> set = StreamSupport.stream(nodes.spliterator(), false)
                    .map(mapper)
                    .collect(Collectors.toSet());
            ...
        }

        ...
    }
Answer from yyunikov on Stack Overflow
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-databind › 2.3.1 › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper - jackson-databind 2.3.1 javadoc
https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind · Current version 2.3.1 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.3.1 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.3.1/package-list ·
🌐
Baeldung
baeldung.com › home › json › jackson › intro to the jackson objectmapper
Intro to the Jackson ObjectMapper | Baeldung
December 9, 2025 - This tutorial focuses on understanding the Jackson ObjectMapper class and how to serialize Java objects into JSON and deserialize JSON string into Java objects.
🌐
Medium
medium.com › @salvipriya97 › java-objectmapper-explained-c33cdc4876d1
Java ObjectMapper explained. In Java, an object mapper is a tool… | by Priya Salvi | Medium
April 21, 2024 - So, in summary, ObjectMapper from Jackson is a powerful tool for converting between Java objects and JSON, enabling seamless data interchange in Java applications.
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › 6-5 › javadoc › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper (The Adobe AEM Quickstart and Web Application.)
ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions. It is also highly customizable to work both with different styles of JSON content, and to support more advanced Object concepts such as polymorphism and Object identity.
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-databind › latest › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper - jackson-databind 2.21.2 javadoc
https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind · Current version 2.21.2 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.21.2 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.21.2/package-list ·
Top answer
1 of 3
2

In your case, I would write a custom JsonDeserializer. Haven't really tested the code, but I think the idea is clear:

    final MyClassDeserializer myClassDeserializer = new MyClassDeserializer();
    final SimpleModule deserializerModule = new SimpleModule();
    deserializerModule.addDeserializer(MyClass.class, myClassDeserializer);

    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(deserializerModule);

And the code for JsonDeserializer:

    public class MyClassDeserializer extends JsonDeserializer<MyClass> {

    @Override
    public MyClass deserialize(final JsonParser jsonParser, final DeserializationContext context)
            throws IOException {
        final JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        final JsonNode sourcesNode = node.get("sources");
        if(node.isArray()) {
            final ArrayNode arrayNode = (ArrayNode) node;
            final Iterable<JsonNode> nodes = arrayNode::elements;
            final Set<Source> set = StreamSupport.stream(nodes.spliterator(), false)
                    .map(mapper)
                    .collect(Collectors.toSet());
            ...
        }

        ...
    }
2 of 3
0

First thing: Your JSON is invalid. There is a comma after the second object in the sources array. This has to be deleted.

Second: I think you didn't choose the right type for your result. What your JSON represents is a map which maps from string to an array of objects. So the type should be something like Map<String, Props[]> (Since you didn't provide the name of your class, I called it Props.

With these considerations you can construct a MapType by using ObjectMappers getTypeFactory() method and deserialize the value using the constructed type like shown below.

ObjectMapper mapper = new ObjectMapper();
TypeFactory typeFactory = mapper.getTypeFactory();
MapType mapType = typeFactory.constructMapType(HashMap.class, String.class, Props[].class);
Map<String, Props[]> map = mapper.readValue(s, mapType);
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-objectmapper.html
Jackson ObjectMapper
Generating JSON from Java objects is also referred to as to serialize Java objects into JSON. The Jackson Object mapper can parse JSON into objects of classes developed by you, or into objects of the built-in JSON tree model explained later in this tutorial. By the way, the reason it is called ObjectMapper is because it maps JSON into Java Objects (deserialization), or Java Objects into JSON (serialization).
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › cloud-service › javadoc › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper (The Adobe Experience Manager SDK 2022.11.9850.20221116T162329Z-220900)
ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions. It is also highly customizable to work both with different styles of JSON content, and to support more advanced Object concepts such as polymorphism and Object identity.
🌐
Oracle
blogs.oracle.com › javamagazine › java-json-serialization-jackson
Looking for a fast, efficient way to serialize and share Java objects? Try Jackson.
Everything so far has involved serialization of Java objects to JSON. What happens when you want to go the other way? Fortunately, the ObjectMapper provides a reading API as well as a writing API.
🌐
Iflow
platform.iflow.cn › en › docs › api-reference
API Reference | 心流开放平台
import com.fasterxml.jackson.databind.ObjectMapper; import java.util.*; // Build message object Map<String, Object> message = new HashMap<>(); message.put("role", "user"); message.put("content", "What opportunities and challenges will the Chinese large model industry face in 2025?"); // Build tool function object Map<String, Object> function = new HashMap<>(); function.put("description", "<string>"); function.put("name", "<string>"); function.put("parameters", new HashMap<>()); function.put("strict", false); Map<String, Object> tool = new HashMap<>(); tool.put("type", "function"); tool.put("fu
🌐
Reddit
reddit.com › r/java › avoid mocking the objectmapper!
r/java on Reddit: Avoid mocking the ObjectMapper!
November 11, 2023 - The issue isn't whether you're mocking first party vs third party code. The reason mocking an ObjectMapper is bad is because there is no reason to do it. ObjectMappers are easily constructible with no transitive dependencies - so why wouldn't you use the real thing?
🌐
Medium
medium.com › @akademixs247 › mastering-jackson-objectmapper-a-comprehensive-guide-for-java-developers-2a4ac1e77949
Mastering Jackson ObjectMapper: A Comprehensive Guide for Java Developers | by Hilary Muiruri | Medium
August 4, 2024 - Jackson is a powerful and efficient library to handle JSON in Java. The ObjectMapper class is the central class that offers the feature of translating Java objects to JSON and JSON to Java objects.
🌐
Northcoder
northcoder.com › post › jackson-object-mapper-which-way-is
Jackson's ObjectMapper and TypeReference | northCoder
January 15, 2021 - Some notes on Jackson’s ObjectMapper, when using it without any custom POJO classes, to deserialize an arbitrary piece of JSON to a Java Map.
🌐
TutorialsPoint
tutorialspoint.com › jackson › jackson_objectmapper.htm
Jackson - ObjectMapper Class
ObjectMapper class ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Plain Old Java Objects), or to and from a general-purpose JSON Tree Model (JsonNode), as well as related functionality for performing conversions.
🌐
GeeksforGeeks
geeksforgeeks.org › java › spring-boot-customize-the-jackson-objectmapper
Spring Boot - Customize the Jackson ObjectMapper - GeeksforGeeks
July 23, 2025 - jackson-datatype-jsr310:support for Java 8 Date and Time API types ... Note: The advantage of this approach is that the Jackson2ObjectMapperBuilder offers a simple and intuitive way to build an ObjectMapper.
🌐
GitHub
github.com › FasterXML › jackson
GitHub - FasterXML/jackson: Main Portal page for the Jackson project · GitHub
These extensions are plug-in Jackson Modules (registered with ObjectMapper.registerModule()), and add support for datatypes of various commonly used Java libraries, by adding serializers and deserializers so that Jackson databind package (ObjectMapper / ObjectReader / ObjectWriter) can read and write these types.
Starred by 9.7K users
Forked by 1.2K users
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-databind › 2.11.4 › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper - jackson-databind 2.11.4 javadoc
https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind · Current version 2.11.4 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.11.4 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.11.4/package-list ·
🌐
Medium
samedesilva.medium.com › jackson-objectmapper-in-rest-assured-8511dd62c608
Jackson ObjectMapper in Rest-Assured | by Sameera De Silva | Medium
March 24, 2025 - Converting a JSON string back into a Java string. public class JsonToStringExample { public static void main(String[] args) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); // JSON string String jsonString = "\"Hello, World!\""; // Notice the double quotes // 🔹 Deserialization: Convert JSON string to Java string String text = objectMapper.readValue(jsonString, String.class); System.out.println("Deserialized Java String: " + text); } }
🌐
GitHub
github.com › joansmith › jackson-databind › blob › master › src › main › java › com › fasterxml › jackson › databind › ObjectMapper.java
jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java at master · joansmith/jackson-databind
* ObjectMapper provides functionality for reading and writing JSON, * either to and from basic POJOs (Plain Old Java Objects), or to and from · * a general-purpose JSON Tree Model ({@link JsonNode}), as well as · * related functionality ...
Author   joansmith