Skip to content

Commit d2ba1ad

Browse files
committed
Start working on #3447
1 parent 7814533 commit d2ba1ad

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

Diff for: src/main/java/com/fasterxml/jackson/databind/node/InternalNodeMapper.java

+41-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import java.io.IOException;
44

5-
import com.fasterxml.jackson.databind.JsonNode;
6-
import com.fasterxml.jackson.databind.ObjectReader;
7-
import com.fasterxml.jackson.databind.ObjectWriter;
5+
import com.fasterxml.jackson.core.JsonGenerator;
6+
7+
import com.fasterxml.jackson.databind.*;
88
import com.fasterxml.jackson.databind.json.JsonMapper;
9+
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
910

1011
/**
11-
* Helper class used to implement <code>toString()</code> method for
12+
* Helper class used to implement {@code toString()} method for
1213
* {@link BaseJsonNode}, by embedding a private instance of
1314
* {@link JsonMapper}, only to be used for node serialization.
1415
*
@@ -27,15 +28,15 @@ final class InternalNodeMapper {
2728

2829
public static String nodeToString(BaseJsonNode n) {
2930
try {
30-
return STD_WRITER.writeValueAsString(n);
31+
return STD_WRITER.writeValueAsString(_wrapper(n));
3132
} catch (IOException e) { // should never occur
3233
throw new RuntimeException(e);
3334
}
3435
}
3536

3637
public static String nodeToPrettyString(BaseJsonNode n) {
3738
try {
38-
return PRETTY_WRITER.writeValueAsString(n);
39+
return PRETTY_WRITER.writeValueAsString(_wrapper(n));
3940
} catch (IOException e) { // should never occur
4041
throw new RuntimeException(e);
4142
}
@@ -50,4 +51,38 @@ public static byte[] valueToBytes(Object value) throws IOException {
5051
public static JsonNode bytesToNode(byte[] json) throws IOException {
5152
return NODE_READER.readValue(json);
5253
}
54+
55+
private static JsonSerializable _wrapper(BaseJsonNode root) {
56+
return new WrapperForSerializer(root);
57+
}
58+
59+
/**
60+
* Intermediate serializer we need to implement non-recursive serialization of
61+
* {@link BaseJsonNode}
62+
*
63+
* @since 2.14
64+
*/
65+
protected static class WrapperForSerializer
66+
extends JsonSerializable.Base
67+
{
68+
protected final BaseJsonNode _root;
69+
70+
public WrapperForSerializer(BaseJsonNode root) {
71+
_root = root;
72+
}
73+
74+
@Override
75+
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
76+
// !!! TODO: placeholder
77+
_root.serialize(gen, serializers);
78+
}
79+
80+
@Override
81+
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer)
82+
throws IOException
83+
{
84+
// Should not really be called given usage, so
85+
serialize(gen, serializers);
86+
}
87+
}
5388
}

0 commit comments

Comments
 (0)