@Override public Leaf deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode tree = (JsonNode) jp.readValueAsTree(); Leaf leaf = new Leaf(); leaf.value = tree.get("value").intValue(); return leaf; }
@Override public ObjectId deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.readValueAsTree(); if (node == null) { return null; } if (node.getNodeType() == JsonNodeType.OBJECT) { return new ObjectId(node.get("$oid").asText()); } return new ObjectId(node.textValue()); }
@Override public SinaContainer getParsedObject() throws InputParserException { try { JsonNode jsonNode = parser.readValueAsTree(); if (jsonNode != null) return new SinaContainer(jsonNode); else throw new InputParserException("Stream has been consumed"); } catch (JsonProcessingException e) { throw new InputParserException("Couldn't parse the activity from stream.", e); } catch (IOException e) { throw new InputParserException("I/O Exception while parsing the activity", e); } }
@Override public E deserialize(JsonParser jp, DeserializationContext ctx) throws IOException { JsonNode node = jp.readValueAsTree(); if (node == null) { return null; } try { return Enum.valueOf(enumClass, node.textValue()); } catch (IllegalArgumentException e) { log.info("Ignoring unknown {} value: {}", enumClass.getSimpleName(), node.textValue()); return fallbackValue; } }
@Override public JSONOptions deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonLocation l = jp.getTokenLocation(); // logger.debug("Reading tree."); TreeNode n = jp.readValueAsTree(); // logger.debug("Tree {}", n); if (n instanceof JsonNode) { return new JSONOptions((JsonNode) n, l); } else { throw new IllegalArgumentException( String.format("Received something other than a JsonNode %s", n)); } }
@Override public ActionItem deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectNode objectNode = jp.readValueAsTree(); JsonNode wrapped = objectNode.get("actionItemType"); JsonParser parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); ActionItemType actionItemType = parser.readValueAs(ActionItemType.class); wrapped = objectNode.get("actionItemId"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); Long actionItemId = parser.getValueAsLong(); wrapped = objectNode.get("actionItemCreateDate"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); Date actionItemCreateDate = new Date(parser.getValueAsLong()); wrapped = objectNode.get("actionItemName"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); String actionItemName = parser.getValueAsString(); wrapped = objectNode.get("actionItemDueDate"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); Date actionItemDueDate = new Date(parser.getValueAsLong()); wrapped = objectNode.get("discussionId"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); Long discussionId = parser.getValueAsLong(); wrapped = objectNode.get("owner"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); MmrActionItemUser owner = parser.readValueAs(MmrActionItemUser.class); wrapped = objectNode.get("assignees"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); List<MmrActionItemUser> assignees = parser.readValueAs(new TypeReference<List<MmrActionItemUser>>() {}); wrapped = objectNode.get("actionItemStatus"); parser = wrapped.traverse(); parser.setCodec(jp.getCodec()); ActionItemStatus actionItemStatus = parser.readValueAs(ActionItemStatus.class); ActionItem actionItem = new UntypedActionItem(); actionItem.setActionItemType(actionItemType); actionItem.setActionItemId(actionItemId); actionItem.setActionItemStatus(actionItemStatus); actionItem.setAssignees(assignees); actionItem.setActionItemCreateDate(actionItemCreateDate); actionItem.setActionItemDueDate(actionItemDueDate); actionItem.setActionItemName(actionItemName); actionItem.setDiscussionId(discussionId); actionItem.setOwner(owner); return actionItem; }
@Override public ServerConfigData deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec codec = jp.getCodec(); ObjectNode serverNode = jp.readValueAsTree(); ServerConfigData data = new ServerConfigData(baseDirSupplier.get(), address, port, development, publicAddress); if (serverNode.hasNonNull("port")) { data.setPort(parsePort(serverNode.get("port"))); } if (serverNode.hasNonNull("address")) { data.setAddress(toValue(codec, serverNode.get("address"), InetAddress.class)); } if (serverNode.hasNonNull("development")) { data.setDevelopment(serverNode.get("development").asBoolean(false)); } if (serverNode.hasNonNull("threads")) { data.setThreads(serverNode.get("threads").asInt(ServerConfig.DEFAULT_THREADS)); } if (serverNode.hasNonNull("publicAddress")) { data.setPublicAddress(toValue(codec, serverNode.get("publicAddress"), URI.class)); } if (serverNode.hasNonNull("maxContentLength")) { data.setMaxContentLength( serverNode.get("maxContentLength").asInt(ServerConfig.DEFAULT_MAX_CONTENT_LENGTH)); } if (serverNode.hasNonNull("maxChunkSize")) { data.setMaxChunkSize( serverNode.get("maxChunkSize").asInt(ServerConfig.DEFAULT_MAX_CHUNK_SIZE)); } if (serverNode.hasNonNull("maxInitialLineLength")) { data.setMaxInitialLineLength( serverNode .get("maxInitialLineLength") .asInt(ServerConfig.DEFAULT_MAX_INITIAL_LINE_LENGTH)); } if (serverNode.hasNonNull("maxHeaderSize")) { data.setMaxHeaderSize( serverNode.get("maxHeaderSize").asInt(ServerConfig.DEFAULT_MAX_HEADER_SIZE)); } if (serverNode.hasNonNull("ssl")) { data.setSslContext(toValue(codec, serverNode.get("ssl"), SSLContext.class)); } if (serverNode.hasNonNull("requireClientSslAuth")) { data.setRequireClientSslAuth(serverNode.get("requireClientSslAuth").asBoolean(false)); } if (serverNode.hasNonNull("baseDir")) { throw new IllegalStateException( "baseDir value cannot be set via config, it must be set directly via ServerConfigBuilder.baseDir()"); } if (serverNode.hasNonNull("connectTimeoutMillis")) { parseOptionalIntValue("connectTimeoutMillis", serverNode.get("connectTimeoutMillis")) .ifPresent(data::setConnectTimeoutMillis); } if (serverNode.hasNonNull("maxMessagesPerRead")) { parseOptionalIntValue("maxMessagesPerRead", serverNode.get("maxMessagesPerRead")) .ifPresent(data::setMaxMessagesPerRead); } if (serverNode.hasNonNull("receiveBufferSize")) { parseOptionalIntValue("receiveBufferSize", serverNode.get("receiveBufferSize")) .ifPresent(data::setReceiveBufferSize); } if (serverNode.hasNonNull("writeSpinCount")) { parseOptionalIntValue("writeSpinCount", serverNode.get("writeSpinCount")) .ifPresent(data::setWriteSpinCount); } return data; }