Search in sources :

Example 21 with MediaContent

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);
    }
}
Also used : SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) MediaContentSerializer(data.media.writeAsArray.MediaContentSerializer) MediaSerializer(data.media.writeAsArray.MediaSerializer) MediaContent(data.media.MediaContent) ImageSerializer(data.media.writeAsArray.ImageSerializer)

Example 22 with MediaContent

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;
}
Also used : Media(data.media.Media) ArrayList(java.util.ArrayList) MediaContent(data.media.MediaContent) JSONLexer(com.alibaba.fastjson.parser.JSONLexer) Image(data.media.Image)

Example 23 with MediaContent

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(']');
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) MediaContent(data.media.MediaContent) Image(data.media.Image)

Aggregations

MediaContent (data.media.MediaContent)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 SerFeatures (serializers.SerFeatures)4 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)3 Image (data.media.Image)3 Media (data.media.Media)2 ArrayList (java.util.ArrayList)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)1 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)1 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 AvroFactory (com.fasterxml.jackson.dataformat.avro.AvroFactory)1 AvroSchema (com.fasterxml.jackson.dataformat.avro.AvroSchema)1 CBORFactory (com.fasterxml.jackson.dataformat.cbor.CBORFactory)1 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)1