List of usage examples for com.fasterxml.jackson.core JsonParser getLongValue
public abstract long getLongValue() throws IOException, JsonParseException;
From source file:com.boundary.zoocreeper.Restore.java
private static BackupZNode readZNode(JsonParser jp, String path) throws IOException { expectNextToken(jp, JsonToken.START_OBJECT); long ephemeralOwner = 0; byte[] data = null; final List<ACL> acls = Lists.newArrayList(); final Set<String> seenFields = Sets.newHashSet(); while (jp.nextToken() != JsonToken.END_OBJECT) { jp.nextValue();/*from www .j a v a2 s.co m*/ final String fieldName = jp.getCurrentName(); seenFields.add(fieldName); if (Backup.FIELD_EPHEMERAL_OWNER.equals(fieldName)) { ephemeralOwner = jp.getLongValue(); } else if (Backup.FIELD_DATA.equals(fieldName)) { if (jp.getCurrentToken() == JsonToken.VALUE_NULL) { data = null; } else { data = jp.getBinaryValue(); } } else if (Backup.FIELD_ACLS.equals(fieldName)) { readACLs(jp, acls); } else { LOGGER.debug("Ignored field: {}", fieldName); } } if (!seenFields.containsAll(REQUIRED_ZNODE_FIELDS)) { throw new IOException("Missing required fields: " + REQUIRED_ZNODE_FIELDS); } return new BackupZNode(path, ephemeralOwner, data, acls); }
From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java
/** Parses the current json token into the corresponding * java object. *//* w w w.jav a 2 s . c o m*/ private static Object getNativeValue(FieldDef fd, JsonToken token, JsonParser p) throws IOException { Object o; if (token == JsonToken.VALUE_STRING) { o = p.getText(); } else if (token == JsonToken.VALUE_NUMBER_INT) { o = Long.valueOf(p.getLongValue()); } else if (token == JsonToken.VALUE_NUMBER_FLOAT) { o = Double.valueOf(p.getDoubleValue()); } else if (token == JsonToken.VALUE_TRUE) { o = Boolean.TRUE; } else if (token == JsonToken.VALUE_FALSE) { o = Boolean.FALSE; } else if (fd.faceted.equals("hierarchy") && token == JsonToken.START_ARRAY) { if (fd.multiValued == false) { List<String> values = new ArrayList<>(); while (true) { token = p.nextToken(); if (token == JsonToken.END_ARRAY) { break; } else if (token != JsonToken.VALUE_STRING) { if (token == JsonToken.START_ARRAY) { fail(fd.name, "expected array of strings, but saw array inside array"); } else { fail(fd.name, "expected array of strings, but saw " + token + " inside array"); } } values.add(p.getText()); } o = values; } else { List<List<String>> values = new ArrayList<>(); while (true) { token = p.nextToken(); if (token == JsonToken.END_ARRAY) { break; } else if (token == JsonToken.START_ARRAY) { List<String> sub = new ArrayList<>(); values.add(sub); while (true) { token = p.nextToken(); if (token == JsonToken.VALUE_STRING) { sub.add(p.getText()); } else if (token == JsonToken.END_ARRAY) { break; } else { fail(fd.name, "expected array of strings or array of array of strings, but saw " + token + " inside inner array"); } } } else if (token == JsonToken.VALUE_STRING) { List<String> sub = new ArrayList<>(); values.add(sub); sub.add(p.getText()); } else if (token == JsonToken.START_ARRAY) { fail(fd.name, "expected array of strings, but saw array inside array"); } else { fail(fd.name, "expected array of strings, but saw " + token + " inside array"); } } o = values; } } else if (fd.valueType == FieldDef.FieldValueType.LAT_LON) { if (token != JsonToken.START_ARRAY) { fail(fd.name, "latlon field must be [lat, lon] value; got " + token); } double[] latLon = new double[2]; token = p.nextToken(); if (token != JsonToken.VALUE_NUMBER_FLOAT) { fail(fd.name, "latlon field must be [lat, lon] value; got " + token); } latLon[0] = p.getDoubleValue(); token = p.nextToken(); if (token != JsonToken.VALUE_NUMBER_FLOAT) { fail(fd.name, "latlon field must be [lat, lon] value; got " + token); } latLon[1] = p.getDoubleValue(); token = p.nextToken(); if (token != JsonToken.END_ARRAY) { fail(fd.name, "latlon field must be [lat, lon] value; got " + token); } o = latLon; } else { String message; if (token == JsonToken.VALUE_NULL) { message = "null field value not supported; just omit this field from the document instead"; } else { message = "value in inner object field value should be string, int/long, float/double or boolean; got " + token; } fail(fd.name, message); // Dead code but compiler disagrees: o = null; } return o; }
From source file:com.netflix.hollow.jsonadapter.util.JsonUtil.java
private static void print(JsonParser parser, JsonToken token, int index, PrintStream out) throws Exception { if (index == 0) System.out.println("\n\n -----"); try {//from w w w . ja va 2 s. c om while (token != null && token != JsonToken.END_OBJECT) { switch (token) { case START_ARRAY: print(index, String.format("fieldname=%s, token=%s", parser.getCurrentName(), token), out); print(parser, parser.nextToken(), index + 1, out); break; case START_OBJECT: print(index, String.format("fieldname=%s, token=%s", parser.getCurrentName(), token), out); print(parser, parser.nextToken(), index + 1, out); break; case VALUE_NUMBER_INT: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getLongValue()), out); break; case VALUE_NUMBER_FLOAT: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getDoubleValue()), out); break; case VALUE_NULL: print(index, String.format("fieldname=%s, token=%s, value=NULL", parser.getCurrentName(), token), out); break; case VALUE_STRING: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getValueAsString()), out); break; case VALUE_FALSE: case VALUE_TRUE: print(index, String.format("fieldname=%s, token=%s, value=%s", parser.getCurrentName(), token, parser.getBooleanValue()), out); break; case FIELD_NAME: //print(index, String.format("fieldname=%s, token=%s", parser.getCurrentName(), token)); break; case END_ARRAY: case END_OBJECT: index--; break; default: } token = parser.nextToken(); } } catch (Exception ex) { ex.printStackTrace(); throw ex; } }
From source file:com.redhat.red.build.koji.model.json.util.SecondsSinceEpochDeserializer.java
@Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { long val = jp.getLongValue(); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(val * 1000L)); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:de.taimos.dvalin.interconnect.model.DateTimeDeserializerWithTZ.java
@Override public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonToken t = jp.getCurrentToken();//from w ww .j a va 2s . com if (t == JsonToken.VALUE_NUMBER_INT) { return new DateTime(jp.getLongValue(), DateTimeZone.forTimeZone(ctxt.getTimeZone())); } if (t == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { // [JACKSON-360] return null; } // catch serialized time zones if ((str.charAt(str.length() - 6) == '+') || (str.charAt(str.length() - 1) == 'Z') || (str.charAt(str.length() - 6) == '-')) { return new DateTime(str); } return new DateTime(str, DateTimeZone.forTimeZone(ctxt.getTimeZone())); } ctxt.handleUnexpectedToken(this.handledType(), jp); // never reached return null; }
From source file:com.inversoft.json.ZonedDateTimeDeserializer.java
@Override public ZonedDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken();//w w w . j a va 2s.c om long value; if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { value = jp.getLongValue(); } else if (t == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { return null; } try { value = Long.parseLong(str); } catch (NumberFormatException e) { throw ctxt.mappingException(handledType()); } } else { throw ctxt.mappingException(handledType()); } return ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), ZoneOffset.UTC); }
From source file:com.spotify.docker.client.jackson.UnixTimestampDeserializer.java
@Override public Date deserialize(final JsonParser parser, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final JsonToken token = parser.getCurrentToken(); if (token == JsonToken.VALUE_STRING) { final String str = parser.getText().trim(); return toDate(Long.parseLong(str)); } else if (token == JsonToken.VALUE_NUMBER_INT) { return toDate(parser.getLongValue()); }//from w w w . j av a 2 s. c om throw ctxt.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected a string or numeric value"); }
From source file:com.ntsync.shared.RequestGenerator.java
private static Restrictions parseRestr(JsonParser jp) throws IOException { int maxContacts = Integer.MAX_VALUE; int maxGroups = Integer.MAX_VALUE; boolean photoSyncSupported = false; Date validUntil = null;/*from ww w. j a va 2 s .c o m*/ while (jp.nextToken() != JsonToken.END_OBJECT) { String configName = jp.getCurrentName(); if (jp.nextToken() == null) { break; } if (PARAM_IS_PHOTO_SYNC_ENABLED.equals(configName)) { photoSyncSupported = jp.getBooleanValue(); } else if (PARAM_MAX_CONTACTS.equals(configName)) { maxContacts = jp.getIntValue(); } else if (PARAM_MAX_GROUPS.equals(configName)) { maxGroups = jp.getIntValue(); } else if (PARAM_VALID_UNTIL.equals(configName)) { validUntil = new Date(jp.getLongValue()); } } return new Restrictions(maxContacts, maxGroups, photoSyncSupported, validUntil); }
From source file:com.taveloper.http.test.pojo.parse.PlusOnersParse.java
public PlusOners readJson(JsonParser in) throws JsonParseException, IOException { // System.out.println("ActivityObjectParse.readJson"); JsonToken curToken = in.nextToken(); PlusOners object = new PlusOners(); while (curToken == JsonToken.FIELD_NAME) { String curName = in.getText(); JsonToken nextToken = in.nextToken(); if ("totalItems".equals(curName)) { object.setTotalItems(in.getLongValue()); }/* w ww . jav a2 s. c om*/ curToken = in.nextToken(); } return object; }
From source file:com.netflix.aegisthus.tools.AegisthusSerializer.java
public Map<String, Object> deserialize(String data) throws IOException { try {/*from w ww. j a va 2 s .com*/ Map<String, Object> map = new LinkedHashMap<String, Object>(); JsonParser jp = jsonFactory.createJsonParser(data); jp.nextToken(); // Object jp.nextToken(); // key map.put(KEY, new DataByteArray(jp.getCurrentName().getBytes())); jp.nextToken(); // object while (jp.nextToken() != JsonToken.END_OBJECT) { String field = jp.getCurrentName(); if (DELETEDAT.equals(field.toUpperCase())) { jp.nextToken(); map.put(DELETEDAT, jp.getLongValue()); } else { jp.nextToken(); while (jp.nextToken() != JsonToken.END_ARRAY) { List<Object> cols = new ArrayList<Object>(); jp.nextToken(); String name = jp.getText(); cols.add(name); jp.nextToken(); cols.add(new DataByteArray(jp.getText().getBytes())); jp.nextToken(); cols.add(jp.getLongValue()); if (jp.nextToken() != JsonToken.END_ARRAY) { String status = jp.getText(); cols.add(status); if ("e".equals(status)) { jp.nextToken(); cols.add(jp.getLongValue()); jp.nextToken(); cols.add(jp.getLongValue()); } else if ("c".equals(status)) { jp.nextToken(); cols.add(jp.getLongValue()); } jp.nextToken(); } map.put(name, cols); } } } return map; } catch (IOException e) { LOG.error(data); throw e; } }