@Override public void parse(T translator, JsonParser jsonParser) throws IOException { JsonParserWrapper wrapper = new JsonParserWrapper(jsonParser); wrapper.setShouldThrowExceptions(shouldThrowFieldExceptions()); if (jsonParser.getCurrentToken() == null) { jsonParser.nextToken(); } if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) { jsonParser.skipChildren(); } else { if (translator instanceof ParseStatusListener) { ((ParseStatusListener) translator).onPreParse(); } while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String key = jsonParser.getCurrentName(); jsonParser.nextToken(); handleParse(translator, wrapper, jsonParser, key); jsonParser.skipChildren(); } if (translator instanceof ParseStatusListener) { ((ParseStatusListener) translator).onParseComplete(); } } }
public static void expect(JsonParser jp, JsonToken tokenType) throws IOException { if (tokenType != jp.getCurrentToken()) throw new IOException( "Expected " + tokenType + ", got: " + jp.getCurrentToken() + " " + jp.getCurrentLocation()); }
private void parseTagList(Reader in, ITagListHandler handler) throws JsonParseException, IOException, RemoteException { JsonFactory f = new JsonFactory(); JsonParser jp = f.createParser(in); String currName; ITag tag = null; List<ITag> tagList = new ArrayList<ITag>(); jp.nextToken(); // will return JsonToken.START_OBJECT (verify?) while (jp.nextToken() != JsonToken.END_OBJECT) { currName = jp.getCurrentName(); jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY if (currName.equals("tags")) { // contains an object // start items while (jp.nextToken() != JsonToken.END_ARRAY) { if (jp.getCurrentToken() == JsonToken.START_OBJECT) { tag = new ITag(); } else if (jp.getCurrentToken() == JsonToken.END_OBJECT) { tagList.add(tag); tag = null; } currName = jp.getCurrentName(); if (currName == null) continue; jp.nextToken(); if (currName.equals("id")) { tag.uid = jp.getText(); int i = tag.uid.indexOf("/label/"); if (i != -1) { tag.label = tag.uid.substring(i + "/label/".length()); // NOTE: @see ReaderManager#updateTagTypes tag.type = ITag.TYPE_TAG_LABEL; } else if (tag.uid.endsWith("state/com.google/starred")) { tag.label = "state/com.google/starred"; tag.type = ITag.TYPE_TAG_STARRED; } } else if (currName.equals("sortid")) { tag.sortid = jp.getText(); } else { jp.skipChildren(); } } handler.tags(tagList); } else { jp.skipChildren(); } } }
public void parseList(List<T> translatorTypes, JsonParser jsonParser) throws IOException { JsonParserWrapper wrapper = new JsonParserWrapper(jsonParser); if (jsonParser.getCurrentToken() == null) { jsonParser.nextToken(); } if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) { while (jsonParser.nextToken() != JsonToken.END_ARRAY) { translatorTypes.add(wrapper.getCurrentValue(getType(), null)); } } }
public ObjectNode deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) { if (jsonparser.getCurrentToken() == JsonToken.START_OBJECT) { jsonparser.nextToken(); return deserializeObject(jsonparser, deserializationcontext, deserializationcontext.getNodeFactory()); } if (jsonparser.getCurrentToken() == JsonToken.FIELD_NAME) { return deserializeObject(jsonparser, deserializationcontext, deserializationcontext.getNodeFactory()); } else { throw deserializationcontext.mappingException(com/fasterxml/jackson/databind/node/ObjectNode); } }
private final byte[] handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext) { if ((paramJsonParser.getCurrentToken() == JsonToken.VALUE_STRING) && (paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) && (paramJsonParser.getText().length() == 0)) return null; if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) throw paramDeserializationContext.mappingException(this._valueClass); JsonToken localJsonToken = paramJsonParser.getCurrentToken(); if ((localJsonToken == JsonToken.VALUE_NUMBER_INT) || (localJsonToken == JsonToken.VALUE_NUMBER_FLOAT)); for (int i = paramJsonParser.getByteValue(); ; i = 0) { return new byte[] { i }; if (localJsonToken != JsonToken.VALUE_NULL) throw paramDeserializationContext.mappingException(this._valueClass.getComponentType()); } }
public void parseArray(T[] translatorTypes, JsonParser jsonParser) throws IOException { JsonParserWrapper wrapper = new JsonParserWrapper(jsonParser); if (jsonParser.getCurrentToken() == null) { jsonParser.nextToken(); } if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) { int count = 0; while (jsonParser.nextToken() != JsonToken.END_ARRAY) { translatorTypes[count] = wrapper.getCurrentValue(getType(), null); count++; } } }
private Map<String, Long> parseUnreadCountList(Reader in) throws JsonParseException, IOException { JsonFactory f = new JsonFactory(); JsonParser jp = f.createParser(in); String currName; String uid = null; Long timestamp = null; int len; String text = null; Map<String, Long> unreadList = new HashMap<String, Long>(); jp.nextToken(); // will return JsonToken.START_OBJECT (verify?) while (jp.nextToken() != JsonToken.END_OBJECT) { currName = jp.getCurrentName(); jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY if (currName.equals("unreadcounts")) { // contains an object // start items while (jp.nextToken() != JsonToken.END_ARRAY) { if (jp.getCurrentToken() == JsonToken.START_OBJECT) { // do nothing } else if (jp.getCurrentToken() == JsonToken.END_OBJECT) { if (!unreadList.containsKey(uid)) unreadList.put(uid, timestamp); } currName = jp.getCurrentName(); if (currName == null) continue; jp.nextToken(); if (currName.equals("id")) { uid = jp.getText(); } else if (currName.equals("newestItemTimestampUsec")) { text = jp.getText(); len = text.length(); if (len > 13) text = jp.getText().substring(0, jp.getText().length() - 6); else if (len > 10) text = jp.getText().substring(0, jp.getText().length() - 3); timestamp = Utils.asLong(text); // millis -> unixtime } else { jp.skipChildren(); } } } else { jp.skipChildren(); } } return unreadList; }
/** * Method for copying contents of the current event <b>and following events that it encloses</b> * the given parser instance points to. * * <p>So what constitutes enclosing? Here is the list of events that have associated enclosed * events that will get copied: * * <ul> * <li>{@link JsonToken#START_OBJECT}: all events up to and including matching (closing) {@link * JsonToken#END_OBJECT} will be copied * <li>{@link JsonToken#START_ARRAY} all events up to and including matching (closing) {@link * JsonToken#END_ARRAY} will be copied * <li>{@link JsonToken#FIELD_NAME} the logical value (which can consist of a single scalar * value; or a sequence of related events for structured types (Json Arrays, Objects)) will * be copied along with the name itself. So essentially the whole <b>field entry</b> (name * and value) will be copied. * </ul> * * <p>After calling this method, parser will point to the <b>last event</b> that was copied. This * will either be the event parser already pointed to (if there were no enclosed events), or the * last enclosed event copied. */ @Override public void copyCurrentStructure(JsonParser jp) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); // Let's handle field-name separately first if (t == JsonToken.FIELD_NAME) { writeFieldName(jp.getCurrentName()); t = jp.nextToken(); // fall-through to copy the associated value } switch (t) { case START_ARRAY: writeStartArray(); while (jp.nextToken() != JsonToken.END_ARRAY) { copyCurrentStructure(jp); } writeEndArray(); break; case START_OBJECT: writeStartObject(); while (jp.nextToken() != JsonToken.END_OBJECT) { copyCurrentStructure(jp); } writeEndObject(); break; default: // others are simple: copyCurrentEvent(jp); } }
/** * Parses generic object. * * @return number of elements written * @throws IOException * @throws JsonParseException * @throws Exception */ private int parseObject() throws IOException, JsonParseException, Exception { int elementsWritten = 0; while (jsonParser.nextToken() != null && jsonParser.getCurrentToken() != END_OBJECT) { if (FIELD_NAME.equals(jsonParser.getCurrentToken())) { String elementName = jsonParser.getCurrentName(); // jump to element value jsonParser.nextToken(); parseElement(elementName); elementsWritten++; } else { throw new ParserException( "Error when parsing. Expected field name got " + jsonParser.getCurrentToken()); } } return elementsWritten; }
@Override public SharedFolderMemberPolicy deserialize(JsonParser p) throws IOException, JsonParseException { SharedFolderMemberPolicy value; boolean collapsed; String tag; if (p.getCurrentToken() == JsonToken.VALUE_STRING) { collapsed = true; tag = getStringValue(p); p.nextToken(); } else { collapsed = false; expectStartObject(p); tag = readTag(p); } if (tag == null) { throw new JsonParseException(p, "Required field missing: " + TAG_FIELD); } else if ("team".equals(tag)) { value = SharedFolderMemberPolicy.TEAM; } else if ("anyone".equals(tag)) { value = SharedFolderMemberPolicy.ANYONE; } else { value = SharedFolderMemberPolicy.OTHER; skipFields(p); } if (!collapsed) { expectEndObject(p); } return value; }
/* * (non-Javadoc) * * @see * org.codehaus.jackson.map.JsonDeserializer#deserialize(org.codehaus.jackson * .JsonParser, org.codehaus.jackson.map.DeserializationContext) */ @Override public NamedErlangFunction deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken token = jp.getCurrentToken(); if (JsonToken.START_OBJECT.equals(token)) { String mod = null; String fun = null; while (!JsonToken.END_OBJECT.equals(token)) { String field = jp.getCurrentName(); if (Constants.FL_SCHEMA_FUN_MOD.equals(field)) { jp.nextToken(); mod = jp.getText(); } else if (Constants.FL_SCHEMA_FUN_FUN.equals(field)) { jp.nextToken(); fun = jp.getText(); } token = jp.nextToken(); } if (mod != null && fun != null) { return new NamedErlangFunction(mod, fun); } else { return null; } } throw ctxt.mappingException(NamedErlangFunction.class); }
@Override public FileMemberRemoveActionResult deserialize(JsonParser p) throws IOException, JsonParseException { FileMemberRemoveActionResult value; boolean collapsed; String tag; if (p.getCurrentToken() == JsonToken.VALUE_STRING) { collapsed = true; tag = getStringValue(p); p.nextToken(); } else { collapsed = false; expectStartObject(p); tag = readTag(p); } if (tag == null) { throw new JsonParseException(p, "Required field missing: " + TAG_FIELD); } else if ("success".equals(tag)) { MemberAccessLevelResult fieldValue = null; fieldValue = MemberAccessLevelResult.Serializer.INSTANCE.deserialize(p, true); value = FileMemberRemoveActionResult.success(fieldValue); } else if ("member_error".equals(tag)) { FileMemberActionError fieldValue = null; expectField("member_error", p); fieldValue = FileMemberActionError.Serializer.INSTANCE.deserialize(p); value = FileMemberRemoveActionResult.memberError(fieldValue); } else { value = FileMemberRemoveActionResult.OTHER; skipFields(p); } if (!collapsed) { expectEndObject(p); } return value; }
@Override public ShareFolderJobStatus deserialize(JsonParser p) throws IOException, JsonParseException { ShareFolderJobStatus value; boolean collapsed; String tag; if (p.getCurrentToken() == JsonToken.VALUE_STRING) { collapsed = true; tag = getStringValue(p); p.nextToken(); } else { collapsed = false; expectStartObject(p); tag = readTag(p); } if (tag == null) { throw new JsonParseException(p, "Required field missing: " + TAG_FIELD); } else if ("in_progress".equals(tag)) { value = ShareFolderJobStatus.IN_PROGRESS; } else if ("complete".equals(tag)) { SharedFolderMetadata fieldValue = null; fieldValue = SharedFolderMetadata.Serializer.INSTANCE.deserialize(p, true); value = ShareFolderJobStatus.complete(fieldValue); } else if ("failed".equals(tag)) { ShareFolderError fieldValue = null; expectField("failed", p); fieldValue = ShareFolderError.Serializer.INSTANCE.deserialize(p); value = ShareFolderJobStatus.failed(fieldValue); } else { throw new JsonParseException(p, "Unknown tag: " + tag); } if (!collapsed) { expectEndObject(p); } return value; }
@Override public Visibility deserialize(JsonParser p) throws IOException, JsonParseException { Visibility value; boolean collapsed; String tag; if (p.getCurrentToken() == JsonToken.VALUE_STRING) { collapsed = true; tag = getStringValue(p); p.nextToken(); } else { collapsed = false; expectStartObject(p); tag = readTag(p); } if (tag == null) { throw new JsonParseException(p, "Required field missing: " + TAG_FIELD); } else if ("public".equals(tag)) { value = Visibility.PUBLIC; } else if ("team_only".equals(tag)) { value = Visibility.TEAM_ONLY; } else if ("password".equals(tag)) { value = Visibility.PASSWORD; } else if ("team_and_password".equals(tag)) { value = Visibility.TEAM_AND_PASSWORD; } else if ("shared_folder_only".equals(tag)) { value = Visibility.SHARED_FOLDER_ONLY; } else { value = Visibility.OTHER; skipFields(p); } if (!collapsed) { expectEndObject(p); } return value; }
@Override public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException { switch (parser.getCurrentToken()) { case START_ARRAY: if (parser.nextToken() == JsonToken.END_ARRAY) { return null; } int year = parser.getIntValue(); parser.nextToken(); int month = parser.getIntValue(); parser.nextToken(); int day = parser.getIntValue(); if (parser.nextToken() != JsonToken.END_ARRAY) { throw context.wrongTokenException(parser, JsonToken.END_ARRAY, "Expected array to end."); } return LocalDate.of(year, month, day); case VALUE_STRING: String string = parser.getText().trim(); if (string.length() == 0) { return null; } return LocalDate.parse(string, ISO_DATE_OPTIONAL_TIME); } throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string."); }
@Override public MembersListError deserialize(JsonParser p) throws IOException, JsonParseException { MembersListError value; boolean collapsed; String tag; if (p.getCurrentToken() == JsonToken.VALUE_STRING) { collapsed = true; tag = getStringValue(p); p.nextToken(); } else { collapsed = false; expectStartObject(p); tag = readTag(p); } if (tag == null) { throw new JsonParseException(p, "Required field missing: " + TAG_FIELD); } else { value = MembersListError.OTHER; skipFields(p); } if (!collapsed) { expectEndObject(p); } return value; }
@Override public Integer deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonToken t = parser.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too return rangeCheckedInteger(parser, context); } if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = parser.getText().trim(); try { int len = text.length(); if (len > 9) { return rangeCheckedInteger(parser, context); } if (len == 0) { return null; } return Integer.valueOf(NumberInput.parseInt(text)); } catch (IllegalArgumentException iae) { throw context.weirdStringException(_valueClass, "not a valid Integer value"); // NOSONAR } } if (t == JsonToken.VALUE_NULL) { return null; } // Otherwise, no can do: throw context.mappingException(_valueClass); }
@Override protected Byte _parseByte(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonToken t = jp.getCurrentToken(); Integer value = null; if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too value = jp.getIntValue(); } else if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = jp.getText().trim(); try { int len = text.length(); if (len == 0) { return getEmptyValue(); } value = NumberInput.parseInt(text); } catch (IllegalArgumentException iae) { throw ctxt.weirdStringException(_valueClass, "not a valid Byte value"); // NOSONAR } } if (value != null) { // So far so good: but does it fit? if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { throw ctxt.weirdStringException( _valueClass, "overflow, value can not be represented as 8-bit value"); } return (byte) (int) value; } if (t == JsonToken.VALUE_NULL) { return getNullValue(); } throw ctxt.mappingException(_valueClass, t); }
/** Sends a POST request to obtain an access token. */ private void obtainAccessToken() { try { token = new OAuth2Token(); error = new OAuth2Error(); /* build the request and send it to the token server */ CloseableHttpClient client = HttpClients.createDefault(); HttpPost request = new HttpPost(tokenServer); request.setEntity(new UrlEncodedFormEntity(Utils.mapToList(tokenParams))); CloseableHttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); /* get the response and parse it */ JsonParser jp = json.getFactory().createParser(entity.getContent()); while (jp.nextToken() != null) { JsonToken jsonToken = jp.getCurrentToken(); switch (jsonToken) { case FIELD_NAME: String name = jp.getCurrentName(); jsonToken = jp.nextToken(); if (name.equals("access_token")) { token.setAccessToken(jp.getValueAsString()); } else if (name.equals("token_type")) { token.setType(OAuth2TokenType.valueOf(jp.getValueAsString().toUpperCase())); } else if (name.equals("expires_in")) { token.setExpiresIn(jp.getValueAsInt()); } else if (name.equals("refresh_token")) { token.setRefreshToken(jp.getValueAsString()); } else if (name.equals("kid")) { token.setKeyId(jp.getValueAsString()); } else if (name.equals("mac_key")) { token.setMacKey(jp.getValueAsString()); } else if (name.equals("mac_algorithm")) { token.setMacAlgorithm(jp.getValueAsString()); } else if (name.equals("error")) { error.setType(OAuth2ErrorType.valueOf(jp.getValueAsString().toUpperCase())); } else if (name.equals("error_description")) { error.setDescription(jp.getValueAsString()); } else if (name.equals("error_uri")) { error.setUri(jp.getValueAsString()); } ready = true; break; default: break; } } jp.close(); response.close(); client.close(); } catch (IOException e) { error.setType(OAuth2ErrorType.SERVER_ERROR); error.setDescription("Failed to obtain access token from the server."); } /* notify all waiting objects */ synchronized (waitObject) { ready = true; waitObject.notifyAll(); } }
private void reportIllegal(JsonParser parser, JsonToken expToken) throws IOException { JsonToken curr = parser.getCurrentToken(); String msg = "Expected token " + expToken + "; got " + curr; if (curr == JsonToken.FIELD_NAME) { msg += " (current field name '" + parser.getCurrentName() + "')"; } msg += ", location: " + parser.getTokenLocation(); throw new IllegalStateException(msg); }
@SuppressWarnings("unchecked") public T[] parseArray(JsonParser parser) throws IOException { List<T> translatorTypeList = new ArrayList<>(); JsonParserWrapper wrapper = new JsonParserWrapper(parser); if (parser.getCurrentToken() == null) { parser.nextToken(); } if (parser.getCurrentToken() == JsonToken.START_ARRAY) { while (parser.nextToken() != JsonToken.END_ARRAY) { translatorTypeList.add(wrapper.getCurrentValue(getType(), null)); } } return translatorTypeList.toArray( (T[]) Array.newInstance(getType(), translatorTypeList.size())); }
@Override public ScimGroup deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ScimGroup group = new ScimGroup(); Map<ScimGroupMember.Role, List<ScimGroupMember>> roles = new HashMap<ScimGroupMember.Role, List<ScimGroupMember>>(); for (ScimGroupMember.Role role : ScimGroupMember.Role.values()) { roles.put(role, new ArrayList<ScimGroupMember>()); } Set<ScimGroupMember> allMembers = new HashSet<ScimGroupMember>(); while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); if ("id".equalsIgnoreCase(fieldName)) { group.setId(jp.readValueAs(String.class)); } else if ("displayname".equalsIgnoreCase(fieldName)) { group.setDisplayName(jp.readValueAs(String.class)); } else if ("meta".equalsIgnoreCase(fieldName)) { group.setMeta(jp.readValueAs(ScimMeta.class)); } else if ("schemas".equalsIgnoreCase(fieldName)) { group.setSchemas(jp.readValueAs(String[].class)); } else { String value = fieldName.substring(0, fieldName.length() - 1); ScimGroupMember.Role role; try { role = ScimGroupMember.Role.valueOf(value.toUpperCase()); } catch (IllegalArgumentException ex) { role = null; } if (role != null) { ScimGroupMember[] members = jp.readValueAs(ScimGroupMember[].class); for (ScimGroupMember member : members) { member.setRoles(new ArrayList<ScimGroupMember.Role>()); } roles.get(role).addAll(Arrays.asList(members)); allMembers.addAll(Arrays.asList(members)); } } } } for (ScimGroupMember member : allMembers) { for (ScimGroupMember.Role role : roles.keySet()) { if (roles.get(role).contains(member)) { member.getRoles().add(role); } } } group.setMembers(new ArrayList<ScimGroupMember>(allMembers)); return group; }
private final boolean[] handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext) { if ((paramJsonParser.getCurrentToken() == JsonToken.VALUE_STRING) && (paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) && (paramJsonParser.getText().length() == 0)) return null; if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) throw paramDeserializationContext.mappingException(this._valueClass); boolean[] arrayOfBoolean = new boolean[1]; arrayOfBoolean[0] = _parseBooleanPrimitive(paramJsonParser, paramDeserializationContext); return arrayOfBoolean; }
public void parseMap(Map<String, T> map, JsonParser jsonParser) throws IOException { JsonParserWrapper wrapper = new JsonParserWrapper(jsonParser); if (jsonParser.getCurrentToken() == null) { jsonParser.nextToken(); } if (jsonParser.getCurrentToken() == com.fasterxml.jackson.core.JsonToken.START_OBJECT) { while (jsonParser.nextToken() != com.fasterxml.jackson.core.JsonToken.END_OBJECT) { String key = jsonParser.getText(); jsonParser.nextToken(); if (jsonParser.getCurrentToken() == com.fasterxml.jackson.core.JsonToken.VALUE_NULL) { map.put(key, null); } else { map.put(key, wrapper.getCurrentValue(getType(), null)); } } } }
/** * Unmarshal. * * @param parser the parser * @param idNull the id null * @param expectedClass the expected class * @return the id * @throws IOException Signals that an I/O exception has occurred. */ public static Id unmarshal(JsonParser parser, @Nullable Id idNull, Class<Id> expectedClass) throws IOException { JsonToken token = parser.getCurrentToken(); if (token == JsonToken.VALUE_EMBEDDED_OBJECT) { ObjectId objectId = (ObjectId) parser.getEmbeddedObject(); return Id.of(objectId.getTime(), objectId.getMachine(), objectId.getInc()); } return Id.fromString(parser.getText()); }
private final String[] handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext) { if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) { if ((paramJsonParser.getCurrentToken() == JsonToken.VALUE_STRING) && (paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) && (paramJsonParser.getText().length() == 0)) return null; throw paramDeserializationContext.mappingException(this._valueClass); } String[] arrayOfString = new String[1]; JsonToken localJsonToken1 = paramJsonParser.getCurrentToken(); JsonToken localJsonToken2 = JsonToken.VALUE_NULL; String str = null; if (localJsonToken1 == localJsonToken2); while (true) { arrayOfString[0] = str; return arrayOfString; str = _parseString(paramJsonParser, paramDeserializationContext); } }
@Override public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (jp.hasCurrentToken() && jp.getCurrentToken().equals(JsonToken.START_OBJECT)) { ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.reader(JsonNode.class).readValue(jp); return node.has(VALUE) ? node.get(VALUE).textValue() : null; } throw ctxt.mappingException("Expected JSON object"); }
@Override public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); return ISODateTimeFormat.dateTimeParser().parseDateTime(str).toLocalDate(); } if (t == JsonToken.VALUE_NUMBER_INT) { return new LocalDate(jp.getLongValue()); } throw ctxt.mappingException(handledType()); }
@Override public Set<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken token = jp.getCurrentToken(); if (token.isScalarValue()) { String list = jp.getText(); list = list.replaceAll("\\s+", ","); return new LinkedHashSet<String>( Arrays.asList(StringUtils.commaDelimitedListToStringArray(list))); } return jp.readValueAs(new TypeReference<Set<String>>() {}); }