List of usage examples for com.fasterxml.jackson.core JsonParser nextToken
public abstract JsonToken nextToken() throws IOException, JsonParseException;
From source file:com.boxedfolder.domain.util.DateTimeDeserializerTests.java
@Test public void testDeserializer() throws Exception { String content = "\"2015-07-22T07:39:16.302Z\""; JsonParser parser = mapper.getFactory().createParser(content); DeserializationContext context = mapper.getDeserializationContext(); parser.nextToken(); DateTime result = deserializer.deserialize(parser, context); assertEquals(dateTime, result);//from w w w. j a v a 2s .c o m parser.close(); }
From source file:com.ntsync.shared.RawContact.java
private static List<RawImData> readImList(String rowId, List<RawImData> imAddresses, JsonParser jp) throws IOException { List<RawImData> newImAddresses = imAddresses; while (jp.nextToken() != JsonToken.END_ARRAY) { ImType type = null;/*from w w w . j av a2s.co m*/ ImProtocolType proType = null; String customProctocolName = null; String imAddress = null; String imTypeLabel = null; boolean isSuperPrimary = false; boolean isPrimary = false; while (jp.nextToken() != JsonToken.END_OBJECT) { String namefield = jp.getCurrentName(); // move to value if (jp.nextToken() == null) { throw new JsonParseException("Invalid JSON-Structure. End of Object missing.", jp.getCurrentLocation()); } if (ContactConstants.DATA.equals(namefield)) { imAddress = jp.getValueAsString(); } else if (ContactConstants.TYPE.equals(namefield)) { type = ImType.fromVal(jp.getValueAsInt()); } else if (ContactConstants.SUPERPRIMARY.equals(namefield)) { isSuperPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.PRIMARY.equals(namefield)) { isPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.LABEL.equals(namefield)) { imTypeLabel = jp.getValueAsString(); } else if (ContactConstants.PROTOCOL_TYPE.equals(namefield)) { proType = ImProtocolType.fromVal(jp.getValueAsInt()); } else if (ContactConstants.PROTOCOL_CUSTOM_PROT.equals(namefield)) { customProctocolName = jp.getValueAsString(); } else { LOG.error(JSON_FIELDNOTRECOGNIZED + rowId + " Fieldname:" + namefield); } } if (newImAddresses == null) { newImAddresses = new ArrayList<RawImData>(); } if (type == null) { type = ImType.TYPE_OTHER; } newImAddresses.add(new RawImData(imAddress, type, imTypeLabel, isPrimary, isSuperPrimary, proType, customProctocolName)); } return newImAddresses; }
From source file:com.taveloper.http.test.pojo.parse.ActivityObjectParse.java
public ActivityObject readJson(JsonParser in) throws JsonParseException, IOException { // System.out.println("ActivityObjectParse.readJson"); JsonToken curToken = in.nextToken(); ActivityObject object = new ActivityObject(); while (curToken == JsonToken.FIELD_NAME) { String curName = in.getText(); JsonToken nextToken = in.nextToken(); if ("content".equals(curName)) { object.setContent(in.getText()); } else if ("plusoners".equals(curName)) { PlusOnersParse plusOnersParse = new PlusOnersParse(); object.setPlusOners(plusOnersParse.readJson(in)); }//from w w w.ja va 2 s. c o m curToken = in.nextToken(); } return object; }
From source file:ijfx.core.metadata.MetaDataDeserializer.java
@Override public MetaDataSet deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException { MetaDataSet m = new MetaDataSet(); while (jp.nextToken() != JsonToken.END_OBJECT) { String fileName = jp.getCurrentName(); jp.nextToken();/* ww w . j a va 2s . co m*/ String value = jp.getText(); m.putGeneric(fileName, value); } return m; }
From source file:ch.rasc.wampspring.message.UnsubscribeMessage.java
public UnsubscribeMessage(JsonParser jp, WampSession wampSession) throws IOException { super(WampMessageType.UNSUBSCRIBE); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }/* w w w . j a v a 2 s . c o m*/ setTopicURI(replacePrefix(jp.getValueAsString(), wampSession)); }
From source file:com.ning.metrics.action.hdfs.data.RowSmile.java
/** * Replace the current row content with a specified DataInput * * @param in DataInput to read// w ww .j a v a2 s.c o m * @throws java.io.IOException generic serialization error */ @Override public void readFields(DataInput in) throws IOException { schema.readFields(in); int numberOfItems = WritableUtils.readVInt(in); int smilePayloadSize = WritableUtils.readVInt(in); int itemsRead = 0; byte[] smilePayload = new byte[smilePayloadSize]; in.readFully(smilePayload); JsonParser jp = objectMapper.getJsonFactory().createJsonParser(smilePayload); while (jp.nextToken() != null && itemsRead < numberOfItems) { objectMapper.readValue(jp, JsonNodeComparable.class); itemsRead++; } jp.close(); }
From source file:io.fabric8.cxf.endpoint.jaxrs.RestJsonSchemaJMXTest.java
private void parseJson(String json) throws Exception { JsonParser parser = new JsonFactory().createParser(json); while (parser.nextToken() != null) { //if it's an invalidate json will throw exception //which could be caught by the test }//from ww w .j av a2s .c o m }
From source file:com.ntsync.shared.RawContact.java
private static List<RawAddressData> readAddressList(String rowId, List<RawAddressData> addresses, JsonParser jp) throws IOException { List<RawAddressData> newAddresses = addresses; while (jp.nextToken() != JsonToken.END_ARRAY) { AddressType type = null;// ww w . jav a 2s . c o m String label = null; String street = null; String city = null; String postcode = null; String country = null; String region = null; String pobox = null; String neighborhood = null; boolean isSuperPrimary = false; boolean isPrimary = false; while (jp.nextToken() != JsonToken.END_OBJECT) { String namefield = jp.getCurrentName(); // move to value if (jp.nextToken() == null) { throw new JsonParseException("Invalid JSON-Structure. End of Array missing.", jp.getCurrentLocation()); } if (ContactConstants.NEIGHBORHOOD.equals(namefield)) { neighborhood = jp.getValueAsString(); } else if (ContactConstants.TYPE.equals(namefield)) { type = AddressType.fromVal(jp.getValueAsInt()); } else if (ContactConstants.SUPERPRIMARY.equals(namefield)) { isSuperPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.PRIMARY.equals(namefield)) { isPrimary = jp.getValueAsBoolean(); } else if (ContactConstants.LABEL.equals(namefield)) { label = jp.getValueAsString(); } else if (ContactConstants.STREET.equals(namefield)) { street = jp.getValueAsString(); } else if (ContactConstants.REGION.equals(namefield)) { region = jp.getValueAsString(); } else if (ContactConstants.CITY.equals(namefield)) { city = jp.getValueAsString(); } else if (ContactConstants.POSTCODE.equals(namefield)) { postcode = jp.getValueAsString(); } else if (ContactConstants.COUNTRY.equals(namefield)) { country = jp.getValueAsString(); } else if (ContactConstants.REGION.equals(namefield)) { region = jp.getValueAsString(); } else if (ContactConstants.POBOX.equals(namefield)) { pobox = jp.getValueAsString(); } else { LOG.error(JSON_FIELDNOTRECOGNIZED + rowId + " Fieldname:" + namefield); } } if (newAddresses == null) { newAddresses = new ArrayList<RawAddressData>(); } if (type == null) { type = AddressType.TYPE_OTHER; } newAddresses.add(new RawAddressData(type, label, isPrimary, isSuperPrimary, street, pobox, neighborhood, city, region, postcode, country)); } return newAddresses; }
From source file:ch.rasc.wampspring.message.CallErrorMessage.java
public CallErrorMessage(JsonParser jp) throws IOException { super(WampMessageType.CALLERROR); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); }//from w w w .j a v a 2 s . c o m this.callID = jp.getValueAsString(); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); } this.errorURI = jp.getValueAsString(); if (jp.nextToken() != JsonToken.VALUE_STRING) { throw new IOException(); } this.errorDesc = jp.getValueAsString(); if (jp.nextToken() != JsonToken.END_ARRAY) { this.errorDetails = jp.readValueAs(Object.class); } else { this.errorDetails = null; } }
From source file:com.netflix.spectator.tdigest.Json.java
private void expect(JsonParser parser, JsonToken expected) throws IOException { JsonToken t = parser.nextToken(); if (t != expected) { String msg = String.format("expected %s, but found %s", expected, t); throw new IllegalArgumentException(msg); }//ww w . j a v a 2 s . co m }