當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParser.readValueAsTree方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.readValueAsTree方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.readValueAsTree方法的具體用法?Java JsonParser.readValueAsTree怎麽用?Java JsonParser.readValueAsTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.core.JsonParser的用法示例。


在下文中一共展示了JsonParser.readValueAsTree方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: _testTokenAccess

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void _testTokenAccess(JsonFactory jf, boolean useStream) throws Exception
{
    final String DOC = "[ ]";
    JsonParser jp = useStream ?
            jf.createParser(ObjectReadContext.empty(), new ByteArrayInputStream(DOC.getBytes("UTF-8")))
            : jf.createParser(ObjectReadContext.empty(), DOC);
    assertNull(jp.currentToken());
    jp.clearCurrentToken();
    assertNull(jp.currentToken());
    assertNull(jp.getEmbeddedObject());
    assertToken(JsonToken.START_ARRAY, jp.nextToken());
    assertToken(JsonToken.START_ARRAY, jp.currentToken());
    jp.clearCurrentToken();
    assertNull(jp.currentToken());
    // Also: no codec defined by default
    try {
        jp.readValueAsTree();
        fail("Should get exception without codec");
    } catch (UnsupportedOperationException e) {
        verifyException(e, "Operation not supported");
    }
    jp.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:TestParserOverrides.java

示例2: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public String[] deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    final List<String> list = new ArrayList<>();
    final JsonNode node = jsonParser.readValueAsTree();
    if (node.isArray()) {
        final Iterator elements = node.elements();
        while (elements.hasNext()) {
            final JsonNode childNode = (JsonNode) elements.next();
            final String value = StringUtils.trimToNull(childNode.asText());
            if (value != null) {
                list.add(value);
            }
        }
    }
    if (list.size() == 0) {
        return null;
    } else {
        return list.toArray(new String[list.size()]);
    }
}
 
開發者ID:stevespringett,項目名稱:Alpine,代碼行數:21,代碼來源:TrimmedStringArrayDeserializer.java

示例3: createObjectNode

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Creates an {@link ObjectNode} based on the given {@code pojo}, copying all its properties to the resulting {@link ObjectNode}.
 *
 * @param pojo a pojo which properties will be populates into the resulting a {@link ObjectNode}
 * @return a {@link ObjectNode} with all the properties from the given pojo
 * @throws IOException if the resulting a {@link ObjectNode} can not be created
 */
public static ObjectNode createObjectNode(Object pojo) throws IOException {
    if (pojo == null) {
        throw new IllegalArgumentException("Pojo can not be null.");
    }

    ObjectNode objectNode = createObjectNode();
    JsonParser jsonParser = mapper.getJsonFactory().createJsonParser(writeValueAsBytes(pojo));
    JsonNode jsonNode = jsonParser.readValueAsTree();

    if (!jsonNode.isObject()) {
        throw new RuntimeException("JsonNode [" + jsonNode + "] is not a object.");
    }

    objectNode.putAll((ObjectNode) jsonNode);

    return objectNode;
}
 
開發者ID:obsidian-toaster-quickstarts,項目名稱:redhat-sso,代碼行數:25,代碼來源:JsonSerialization.java

示例4: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public CommentCollectionResource deserialize(JsonParser jp, DeserializationContext ctxt)
		throws IOException, JsonProcessingException {
	CommentCollectionResource commentArrayResource = new CommentCollectionResource();
	CommentResource commentResource = null;

	JsonNode jsonNode = jp.readValueAsTree();

	for (JsonNode childNode : jsonNode) {
		if (childNode.has(CommentResource.JP_TASKID)) {
			commentResource = new CommentResource();
			commentResource.setTaskId(childNode.get(CommentResource.JP_TASKID).asText());
			commentResource.setComment(childNode.get(CommentResource.JP_COMMENT).asText());
			commentResource.setPosted(new Date(childNode.get(CommentResource.JP_POSTED).asLong()));

			commentArrayResource.addComment(commentResource);
		}
	}
	return commentArrayResource;

}
 
開發者ID:anilallewar,項目名稱:microservices-basics-spring-boot,代碼行數:22,代碼來源:CommentCollectionResource.java

示例5: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public CommitMessageDto deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    final JsonNode jsonNode = p.readValueAsTree();
    final JsonNode summary = jsonNode.get("summary");
    if (summary == null || summary.textValue() == null) {
        ctxt.reportInputMismatch(CommitMessageDto.class, "commit message should have a summary.");
        // should never reach here
        throw new Error();
    }

    final String detail = jsonNode.get("detail") == null ? "" : jsonNode.get("detail").textValue();
    final JsonNode markupNode = jsonNode.get("markup");
    final Markup markup = Markup.parse(markupNode == null ? "unknown" : markupNode.textValue());
    return new CommitMessageDto(summary.textValue(), detail, markup);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:16,代碼來源:CommitMessageDtoDeserializer.java

示例6: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Step deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    ObjectNode node = jp.readValueAsTree();
    JsonNode stepKind = node.get(STEP_KIND);
    if (stepKind != null) {
        String value = stepKind.textValue();
        Class<? extends Step> resourceType = getTypeForName(value);
        if (resourceType == null) {
            throw ctxt.mappingException("No step type found for kind:" + value);
        }

        return jp.getCodec().treeToValue(node, resourceType);
    }
    return null;
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:16,代碼來源:StepDeserializer.java

示例7: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public ErrorData deserialize(JsonParser jp, DeserializationContext context) throws IOException {
	JsonNode errorNode = jp.readValueAsTree();
	String id = SerializerUtil.readStringIfExists(ErrorDataSerializer.ID, errorNode);
	String aboutLink = readAboutLink(errorNode);
	String status = SerializerUtil.readStringIfExists(ErrorDataSerializer.STATUS, errorNode);
	String code = SerializerUtil.readStringIfExists(ErrorDataSerializer.CODE, errorNode);
	String title = SerializerUtil.readStringIfExists(ErrorDataSerializer.TITLE, errorNode);
	String detail = SerializerUtil.readStringIfExists(ErrorDataSerializer.DETAIL, errorNode);
	Map<String, Object> meta = readMeta(errorNode, jp);
	String sourcePointer = readSourcePointer(errorNode);
	String sourceParameter = readSourceParameter(errorNode);
	return new ErrorData(id, aboutLink, status, code, title, detail, sourcePointer, sourceParameter, meta);
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:15,代碼來源:ErrorDataDeserializer.java

示例8: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@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));
      }
    }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:14,代碼來源:JSONOptions.java

示例9: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public TraceInfoHeaders deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
	JsonNode root = p.readValueAsTree();
    Map<String, List<String>> request = parse(root.get("request"));
    Map<String, List<String>> response = parse(root.get("response"));

    return new TraceInfoHeaders(request, response);
}
 
開發者ID:vianneyfaivre,項目名稱:Persephone,代碼行數:9,代碼來源:TraceService.java

示例10: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    JsonNode node = jsonParser.readValueAsTree();
    if (node.asText().isEmpty()) {
        return null;
    }
    return node.asText();
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:9,代碼來源:AbstractLandGebiedMixIn.java

示例11: validateJson

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Parse a JSON object
 * @param jp the JSON parse
 * @return the JSON node
 * @throws IOException
 */
protected JsonNode validateJson(JsonParser jp) throws IOException {
    JsonNode parsed = null;
    
    try {
        parsed = jp.readValueAsTree();
    } catch (JsonProcessingException e) {
        System.err.println("Could not parse JSON: " + e.getMessage());
        return null;
    }  
    return parsed;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:18,代碼來源:ShellCommand.java

示例12: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    final JsonNode node = jsonParser.readValueAsTree();
    return StringUtils.trimToNull(node.asText());
}
 
開發者ID:stevespringett,項目名稱:Alpine,代碼行數:6,代碼來源:TrimmedStringDeserializer.java

示例13: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Revision deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
    final JsonNode node = p.readValueAsTree();
    if (node.isNumber()) {
        validateRevisionNumber(ctx, node, "major", false);
        return new Revision(node.intValue());
    }

    if (node.isTextual()) {
        try {
            return new Revision(node.textValue());
        } catch (IllegalArgumentException e) {
            ctx.reportInputMismatch(Revision.class, e.getMessage());
            // Should never reach here.
            throw new Error();
        }
    }

    if (!node.isObject()) {
        ctx.reportInputMismatch(Revision.class,
                                "A revision must be a non-zero integer or " +
                                "an object that contains \"major\" and \"minor\" properties.");
        // Should never reach here.
        throw new Error();
    }

    final JsonNode majorNode = node.get("major");
    final JsonNode minorNode = node.get("minor");
    final int major;

    validateRevisionNumber(ctx, majorNode, "major", false);
    major = majorNode.intValue();
    if (minorNode != null) {
        validateRevisionNumber(ctx, minorNode, "minor", true);
        if (minorNode.intValue() != 0) {
            ctx.reportInputMismatch(Revision.class,
                                    "A revision must not have a non-zero \"minor\" property.");
        }
    }

    return new Revision(major);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:43,代碼來源:RevisionJsonDeserializer.java

示例14: readToJsonNode

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Decode the bytes to Json object.
 * @param in input of bytes
 * @param out ouput of Json object list
 * @param jrContext context for the last decoding process
 * @throws IOException IOException
 * @throws JsonParseException JsonParseException
 */
public static void readToJsonNode(ByteBuf in, List<Object> out, JsonReadContext jrContext)
        throws JsonParseException, IOException {
    int lastReadBytes = jrContext.getLastReadBytes();
    if (lastReadBytes == 0) {
        if (in.readableBytes() < 4) {
            return;
        }
        checkEncoding(in);
    }

    int i = lastReadBytes + in.readerIndex();
    Stack<Byte> bufStack = jrContext.getBufStack();
    for (; i < in.writerIndex(); i++) {
        byte b = in.getByte(i);
        switch (b) {
        case '{':
            if (!isDoubleQuote(bufStack)) {
                bufStack.push(b);
                jrContext.setStartMatch(true);
            }
            break;
        case '}':
            if (!isDoubleQuote(bufStack)) {
                bufStack.pop();
            }
            break;
        case '"':
            if (in.getByte(i - 1) != '\\') {
                if (!bufStack.isEmpty() && bufStack.peek() != '"') {
                    bufStack.push(b);
                } else {
                    bufStack.pop();
                }
            }
            break;
        default:
            break;
        }

        if (jrContext.isStartMatch() && bufStack.isEmpty()) {
            ByteBuf buf = in.readSlice(i - in.readerIndex() + 1);
            JsonParser jf = new MappingJsonFactory().createParser(new ByteBufInputStream(buf));
            JsonNode jsonNode = jf.readValueAsTree();
            out.add(jsonNode);
            lastReadBytes = 0;
            jrContext.setLastReadBytes(lastReadBytes);
            break;
        }
    }

    if (i >= in.writerIndex()) {
        lastReadBytes = in.readableBytes();
        jrContext.setLastReadBytes(lastReadBytes);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:64,代碼來源:JsonRpcReaderUtil.java


注:本文中的com.fasterxml.jackson.core.JsonParser.readValueAsTree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。