Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a28665e

Browse files
committed
improved RawJson serialization
1 parent 535b981 commit a28665e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

‎core/src/main/java/com/arangodb/internal/serde/InternalSerializers.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import com.arangodb.internal.ArangoRequestParam;
77
import com.arangodb.util.RawJson;
88
import com.arangodb.internal.InternalRequest;
9+
import com.fasterxml.jackson.core.JsonFactory;
910
import com.fasterxml.jackson.core.JsonGenerator;
1011
import com.fasterxml.jackson.core.JsonParser;
1112
import com.fasterxml.jackson.databind.JsonSerializer;
1213
import com.fasterxml.jackson.databind.SerializerProvider;
1314

1415
import java.io.IOException;
16+
import java.nio.charset.StandardCharsets;
1517
import java.util.Collection;
1618
import java.util.HashMap;
1719
import java.util.Map;
@@ -22,9 +24,13 @@ public final class InternalSerializers {
2224
static final JsonSerializer<RawJson> RAW_JSON_SERIALIZER = new JsonSerializer<RawJson>() {
2325
@Override
2426
public void serialize(RawJson value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
25-
try (JsonParser parser = SerdeUtils.INSTANCE.getJsonMapper().createParser(value.get())) {
26-
parser.nextToken();
27-
gen.copyCurrentStructure(parser);
27+
if (JsonFactory.FORMAT_NAME_JSON.equals(gen.getCodec().getFactory().getFormatName())) {
28+
gen.writeRawValue(new RawUserDataValue(value.get().getBytes(StandardCharsets.UTF_8)));
29+
} else {
30+
try (JsonParser parser = SerdeUtils.INSTANCE.getJsonMapper().createParser(value.get())) {
31+
parser.nextToken();
32+
gen.copyCurrentStructure(parser);
33+
}
2834
}
2935
}
3036
};

‎core/src/main/java/com/arangodb/internal/serde/SerdeUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.arangodb.entity.BaseEdgeDocument;
66
import com.arangodb.util.RawBytes;
77
import com.arangodb.util.RawJson;
8+
import com.fasterxml.jackson.core.JsonFactory;
89
import com.fasterxml.jackson.core.JsonParser;
910
import com.fasterxml.jackson.core.JsonProcessingException;
1011
import com.fasterxml.jackson.core.JsonToken;
@@ -98,7 +99,6 @@ public String writeJson(final JsonNode data) {
9899
* @param parser JsonParser with current token pointing to the node to extract
99100
* @return byte array
100101
*/
101-
// TODO: move to InternalSerdeImpl, non-static, keep reference to serde to check content-type
102102
public static byte[] extractBytes(JsonParser parser) throws IOException {
103103
JsonToken t = parser.currentToken();
104104
if (t.isStructEnd() || t == JsonToken.FIELD_NAME) {
@@ -119,7 +119,7 @@ public static byte[] extractBytes(JsonParser parser) throws IOException {
119119
}
120120
}
121121
parser.finishToken();
122-
if ("JSON".equals(parser.getCodec().getFactory().getFormatName())) {
122+
if (JsonFactory.FORMAT_NAME_JSON.equals(parser.getCodec().getFactory().getFormatName())) {
123123
end = (int) parser.currentLocation().getByteOffset();
124124
}
125125
return Arrays.copyOfRange(data, start, end);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /