Skip to content

Commit

Permalink
Upgrade DSL JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaldekloe committed Jul 3, 2020
1 parent fa60184 commit 65c0bf0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
Binary file removed tpc/lib/dsl-json-1.7.2.jar
Binary file not shown.
Binary file added tpc/lib/dsl-json-1.9.5.jar
Binary file not shown.
Binary file removed tpc/lib/dsl-json-java8-1.7.2.jar
Binary file not shown.
27 changes: 10 additions & 17 deletions tpc/src/serializers/dsljson/DSLJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import serializers.*;

import com.dslplatform.json.*;
import com.dslplatform.json.runtime.Settings;

import java.io.ByteArrayOutputStream;

public class DSLJson {

Expand All @@ -17,37 +18,29 @@ public static void register(final TestGroups groups) {
}

static class DSLJsonSerializer extends Serializer<MediaContent> {
private final JsonWriter writer;
private final JsonReader reader;
private final JsonWriter.WriteObject<MediaContent> encoder;
private final JsonReader.ReadObject<MediaContent> decoder;
private final boolean asArray;
final boolean asArray;
final DslJson<Object> json;
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();

DSLJsonSerializer(boolean asArray) {
DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().allowArrayFormat(asArray).includeServiceLoader());
this.writer = dslJson.newWriter();
this.reader = dslJson.newReader();
this.encoder = dslJson.tryFindWriter(MediaContent.class);
this.decoder = dslJson.tryFindReader(MediaContent.class);
this.asArray = asArray;
this.json = new DslJson<Object>(new DslJson.Settings<>().allowArrayFormat(asArray).includeServiceLoader());
}

@Override
public String getName() {
return asArray ? "json-array/dsl-json/databind" : "json/dsl-json/databind";
return this.asArray ? "json-array/dsl-json/databind" : "json/dsl-json/databind";
}

@Override
public MediaContent deserialize(final byte[] array) throws Exception {
reader.process(array, array.length).read();
return decoder.read(reader);
return json.deserialize(MediaContent.class, array, array.length);
}

@Override
public byte[] serialize(final MediaContent content) throws Exception {
writer.reset();
encoder.write(writer, content);
return writer.toByteArray();
json.serialize(content, buffer);
return buffer.toByteArray();
}
}
}

0 comments on commit 65c0bf0

Please sign in to comment.