Developer
News and Updates
Get Support
Sign in
Get Support
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Last updated Sep 1, 2026

Use Jackson 1 with ADF Builder Java

Change Log

Description

Jackson v1 is no longer supported by this library. Consumers are encouraged to upgrade to Jackson v2, instead. The following Java code is provided as an unmaintained example of how to implement this yourself.

Example

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

import com.atlassian.adf.model.node.Doc;
import com.atlassian.adf.parser.AdfParser;
import com.atlassian.adf.parser.JsonParser;
import com.atlassian.annotations.PublicApi;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import java.io.IOException;
import java.util.Map;

import static java.util.Objects.requireNonNull;

public class AdfJackson1 implements AdfParser<String> {
    private static final TypeReference<Map<String, Object>> TYPE_REFERENCE = new TypeReference<>() {
    };

    private final ObjectMapper mapper;
    private final JsonParser jsonParser;
    private final boolean pretty;

    public AdfJackson1() {
        this(new ObjectMapper(), false);
    }

    public AdfJackson1(ObjectMapper mapper) {
        this(mapper, false);
    }

    public AdfJackson1(ObjectMapper mapper, boolean pretty) {
        this.mapper = requireNonNull(mapper, "mapper");
        this.pretty = pretty;
        this.jsonParser = new Jackson1JsonParser(pretty);
    }

    public ObjectMapper mapper() {
        return mapper;
    }

    @Override
    public JsonParser jsonParser() {
        return jsonParser;
    }

    public String marshall(Doc doc) {
        Map<String, ?> map = doc.toMap();
        return jsonParser.toJson(map);
    }

    public Doc unmarshall(String json) {
        Map<String, ?> map = jsonParser.fromJson(json);
        return Doc.parse(map);
    }

    /**
     * The same underlying parser, but using concrete {@code JsonNode} objects as the transport format
     * instead of JSON strings.
     */
    public AdfParser<JsonNode> useJsonNode() {
        return new UseJsonNode();
    }

    /**
     * The same underlying parser, but using pretty JSON formatting when rendering it as a string.
     */
    public AdfJackson1 pretty() {
        return this.pretty ? this : new AdfJackson1(mapper, true);
    }

    private class UseJsonNode implements AdfParser<JsonNode> {
        @Override
        public JsonParser jsonParser() {
            return jsonParser;
        }

        @Override
        public JsonNode marshall(Doc doc) {
            Map<String, ?> map = doc.toMap();
            return mapper.valueToTree(map);
        }

        @Override
        public Doc unmarshall(JsonNode json) {
            if (!json.isObject()) {
                throw new IllegalArgumentException("Invalid JSON input: " + json.asToken());
            }
            Map<String, ?> map = mapper.convertValue(json, TYPE_REFERENCE);
            return Doc.parse(map);
        }
    }

    private class Jackson1JsonParser implements JsonParser {
        private final boolean pretty;

        Jackson1JsonParser(boolean pretty) {
            this.pretty = pretty;
        }

        @Override
        public String toJson(Map<String, ?> map) {
            try {
                return pretty
                        ? mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map)
                        : mapper.writeValueAsString(map);
            } catch (IOException e) {
                throw new IllegalStateException("Invalid JSON output", e);
            }
        }

        @Override
        public Map<String, ?> fromJson(String json) {
            try {
                return mapper.readValue(json, TYPE_REFERENCE);
            } catch (IOException e) {
                throw new IllegalArgumentException("Invalid JSON input", e);
            }
        }
    }
}

Tests

Note that these require a test dependency on the adf-builder-java-tck module:

1
2
3
4
5
6
7
8
import com.atlassian.adf.tck.AdfTckTest;

public class AdfJackson1StringTest extends AdfTckTest<String> {
    public AdfJackson1StringTest() {
        super(new AdfJackson1());
    }
}
1
2
3
4
5
6
7
8
9
import com.atlassian.adf.tck.AdfTckTest;
import org.codehaus.jackson.JsonNode;

public class AdfJackson1NodeTest extends AdfTckTest<JsonNode> {
    public AdfJackson1NodeTest() {
        super(new AdfJackson1().useJsonNode());
    }
}

Rate this page: