List of usage examples for com.fasterxml.jackson.core JsonParser getCurrentLocation
public abstract JsonLocation getCurrentLocation();
From source file:com.google.openrtb.json.OpenRtbJsonExtComplexReader.java
@SuppressWarnings("unchecked") private void readRepeated(EB msg, JsonParser par) throws IOException { par.nextToken();// ww w. java 2s . com JsonToken tokLast = par.getCurrentToken(); JsonLocation locLast = par.getCurrentLocation(); for (startArray(par); endArray(par); par.nextToken()) { boolean objRead = false; XB ext = (XB) key.getMessageDefaultInstance().toBuilder(); for (startObject(par); endObject(par); par.nextToken()) { read(ext, par); JsonToken tokNew = par.getCurrentToken(); JsonLocation locNew = par.getCurrentLocation(); if (tokNew != tokLast || !locNew.equals(locLast)) { objRead = true; } tokLast = tokNew; locLast = locNew; } if (objRead) { msg.addExtension(key, ext.build()); } } }
From source file:fi.hsl.parkandride.front.geojson.GeojsonDeserializer.java
@Override public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { try {/*w w w. j av a 2 s.c om*/ return jsonMapper.fromJson(jp.readValueAsTree().toString(), type); } catch (JsonException e) { throw new JsonMappingException(e.getMessage(), jp.getCurrentLocation(), e.getCause()); } }
From source file:ca.ualberta.physics.cssdp.util.JSONDateTimeDeserializer.java
@Override public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { try {/*from w ww .ja v a 2 s . co m*/ return ISODateTimeFormat.dateTimeParser().parseDateTime(jp.getText()); } catch (Exception e) { e.printStackTrace(); throw new JsonParseException(e.getMessage(), jp.getCurrentLocation()); } }
From source file:ca.ualberta.physics.cssdp.util.JSONLocalDateTimeDeserializer.java
@Override public LocalDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { try {/*w w w.j a v a 2 s. c om*/ return ISODateTimeFormat.dateTimeParser().parseLocalDateTime(jp.getText()); } catch (Exception e) { e.printStackTrace(); throw new JsonParseException(e.getMessage(), jp.getCurrentLocation()); } }
From source file:com.google.openrtb.json.OpenRtbJsonExtComplexReader.java
@SuppressWarnings("unchecked") private void readSingle(EB msg, JsonParser par, XB ext) throws IOException { if (isJsonObject) { startObject(par);//from w ww. ja v a2 s.c o m } boolean extRead = false; JsonToken tokLast = par.getCurrentToken(); JsonLocation locLast = par.getCurrentLocation(); while (endObject(par)) { read(ext, par); if (par.getCurrentToken() != tokLast || !par.getCurrentLocation().equals(locLast)) { extRead = true; par.nextToken(); tokLast = par.getCurrentToken(); locLast = par.getCurrentLocation(); } else { break; } } if (extRead) { msg.setExtension(key, ext.build()); } if (isJsonObject) { par.nextToken(); } }
From source file:com.nesscomputing.httpclient.response.StreamedJsonContentConverter.java
private void expect(final JsonParser jp, final JsonToken token, final JsonToken expected) throws JsonParseException { if (!Objects.equal(token, expected)) { throw new JsonParseException(String.format("Expected %s, found %s", expected, token), jp.getCurrentLocation()); }/* w ww .j a v a 2 s .c o m*/ }
From source file:com.opentable.jaxrs.StreamedJsonResponseConverter.java
private <T> void doRead(Callback<T> callback, TypeReference<T> type, final JsonParser jp) throws IOException { expect(jp, jp.nextToken(), JsonToken.START_OBJECT); expect(jp, jp.nextToken(), JsonToken.FIELD_NAME); if (!"results".equals(jp.getCurrentName())) { throw new JsonParseException("expecting results field", jp.getCurrentLocation()); }//from ww w . j av a 2 s .c o m expect(jp, jp.nextToken(), JsonToken.START_ARRAY); // As noted in a well-hidden comment in the MappingIterator constructor, // readValuesAs requires the parser to be positioned after the START_ARRAY // token with an empty current token jp.clearCurrentToken(); Iterator<T> iter = jp.readValuesAs(type); while (iter.hasNext()) { try { callback.call(iter.next()); } catch (CallbackRefusedException e) { LOG.debug("callback refused execution, finishing.", e); return; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException("Callback interrupted", e); } catch (Exception e) { Throwables.propagateIfPossible(e, IOException.class); throw new IOException("Callback failure", e); } } if (jp.nextValue() != JsonToken.VALUE_TRUE || !jp.getCurrentName().equals("success")) { throw new IOException("Streamed receive did not terminate normally; inspect server logs for cause."); } }
From source file:com.joliciel.jochre.search.webClient.SearchResults.java
public SearchResults(String json) { try {//w w w . j a v a 2s .com scoreDocs = new ArrayList<SearchDocument>(); Reader reader = new StringReader(json); JsonFactory jsonFactory = new JsonFactory(); // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory JsonParser jsonParser = jsonFactory.createJsonParser(reader); // Sanity check: verify that we got "Json Object": if (jsonParser.nextToken() != JsonToken.START_OBJECT) throw new RuntimeException("Expected START_OBJECT, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String baseName = jsonParser.getCurrentName(); LOG.debug("Found baseName: " + baseName); if (jsonParser.nextToken() != JsonToken.START_OBJECT) throw new RuntimeException("Expected START_OBJECT, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); SearchDocument doc = new SearchDocument(baseName, jsonParser); scoreDocs.add(doc); } // next scoreDoc } catch (JsonParseException e) { LOG.error(e); throw new RuntimeException(e); } catch (IOException e) { LOG.error(e); throw new RuntimeException(e); } }
From source file:com.redhat.red.build.koji.model.json.util.BuildSourceDeserializer.java
@Override public BuildSource deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String urlAndRev = jp.getText(); String[] parts = urlAndRev.split("#"); if (parts.length < 2 || isEmpty(parts[0]) || isEmpty(parts[1])) { throw new KojiJsonException( "Invalid build-source: '" + urlAndRev + "'. Must be of format '<base-url>#<commit-ish>'", jp.getCurrentLocation()); }//w w w . j av a 2 s .co m return new BuildSource(parts[0], parts[1]); }
From source file:org.springframework.social.bitbucket.api.impl.UTCDateDeserializer.java
@Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { try {// w w w .j av a2s . co m SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.parse(jp.getText()); } catch (ParseException e) { throw new JsonParseException("Can't parse date : " + jp.getText(), jp.getCurrentLocation()); } }