Example usage for com.fasterxml.jackson.dataformat.smile SmileFactory createParser

List of usage examples for com.fasterxml.jackson.dataformat.smile SmileFactory createParser

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.smile SmileFactory createParser.

Prototype

@Override
    public SmileParser createParser(byte[] data) throws IOException, JsonParseException 

Source Link

Usage

From source file:com.basistech.AfterburnerOopsTest.java

@Test
public void oops() throws Exception {
    SmileFactory smileFactory = new SmileFactory();
    ObjectMapper mapper = new ObjectMapper(smileFactory);
    mapper = AnnotatedDataModelModule.setupObjectMapper(mapper);

    EntityMention em = new EntityMention();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    List<EntityMention> mentions = Lists.newArrayList();
    mentions.add(em);/* w w w  . j av a  2  s  . c o m*/
    mapper.writeValue(byteArrayOutputStream, mentions);

    mapper = AnnotatedDataModelModule.setupObjectMapper(new ObjectMapper(smileFactory));
    mapper.registerModule(new AfterburnerModule());
    JsonParser jp = smileFactory.createParser(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
    jp.setCodec(mapper);

    JsonToken current;
    current = jp.nextToken();
    if (current != JsonToken.START_ARRAY) {
        System.err.println("Error: root should be array: quiting.");
        return;
    }

    while (jp.nextToken() != JsonToken.END_ARRAY) {
        jp.readValueAs(EntityMention.class);
    }

}