use of data.media.MediaContent in project fastjson by alibaba.
the class BenchmarkMain_EishayEncode_WriteAsArray method main.
public static void main(String[] args) throws Exception {
SerializeConfig config = SerializeConfig.getGlobalInstance();
config.put(MediaContent.class, new MediaContentSerializer());
config.put(Media.class, new MediaSerializer());
config.put(Image.class, new ImageSerializer());
System.out.println(System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
System.out.println(arguments);
MediaContent content = EishayDecodeBytes.instance.getContent();
String text = encode(content);
System.out.println(text);
for (int i = 0; i < 10; ++i) {
perf(text);
}
}
use of data.media.MediaContent in project fastjson by alibaba.
the class MediaContentDeserializer method deserialze.
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.getLexer();
parser.accept(JSONToken.LBRACKET, JSONToken.LBRACKET);
Media media = mediaDeser.deserialze(parser, Media.class, "media");
parser.accept(JSONToken.COMMA, JSONToken.LBRACKET);
parser.accept(JSONToken.LBRACKET, JSONToken.LBRACKET);
List<Image> images = new ArrayList<Image>();
int index = 0;
for (; ; ) {
Image image = imageDesc.deserialze(parser, Image.class, index);
images.add(image);
index++;
if (lexer.token() == JSONToken.COMMA) {
lexer.nextToken(JSONToken.LBRACKET);
} else {
break;
}
}
parser.accept(JSONToken.RBRACKET, JSONToken.RBRACKET);
parser.accept(JSONToken.RBRACKET, JSONToken.EOF);
MediaContent content = new MediaContent();
content.setMedia(media);
content.setImages(images);
return (T) content;
}
use of data.media.MediaContent in project fastjson by alibaba.
the class MediaContentSerializer method write.
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
MediaContent entity = (MediaContent) object;
SerializeWriter out = serializer.getWriter();
out.write('[');
mediaSerilaizer.write(serializer, entity.getMedia(), "media", Media.class, 0);
out.write(',');
out.write('[');
for (int i = 0; i < entity.getImages().size(); ++i) {
if (i != 0) {
out.write(',');
}
Image image = entity.getImages().get(i);
imageSerilaizer.write(serializer, image, i, fieldType, 0);
}
out.write(']');
out.write(']');
}
Aggregations