Java tutorial
/****************************************************************************** ** This data and information is proprietary to, and a valuable trade secret ** of, Basis Technology Corp. It is given in confidence by Basis Technology ** and may only be used as permitted under the license agreement under which ** it has been distributed, and in no other way. ** ** Copyright (c) 2014 Basis Technology Corporation All rights reserved. ** ** The technical data and information provided herein are provided with ** `limited rights', and the computer software provided herein is provided ** with `restricted rights' as those terms are defined in DAR and ASPR ** 7-104.9(a). ******************************************************************************/ package com.basistech; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.fasterxml.jackson.module.afterburner.AfterburnerModule; import com.google.common.collect.Lists; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.List; /** * Created by benson on 9/26/14. */ public class AfterburnerOopsTest { @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); 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); } } }