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


Java DeserializationContext.reportInputMismatch方法代碼示例

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


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

示例1: validateRevisionNumber

import com.fasterxml.jackson.databind.DeserializationContext; //導入方法依賴的package包/類
private static void validateRevisionNumber(DeserializationContext ctx, JsonNode node,
                                           String type, boolean zeroAllowed) throws JsonMappingException {
    if (node == null) {
        ctx.reportInputMismatch(Revision.class, "missing %s revision number", type);
        // Should never reach here.
        throw new Error();
    }

    if (!node.canConvertToInt() || !zeroAllowed && node.intValue() == 0) {
        ctx.reportInputMismatch(Revision.class,
                                "A %s revision number must be %s integer.",
                                type, zeroAllowed ? "an" : "a non-zero");
        // Should never reach here.
        throw new Error();
    }
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:17,代碼來源:RevisionJsonDeserializer.java

示例2: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //導入方法依賴的package包/類
@Override
public SimpleSession deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    try (ByteArrayInputStream bais =
                 new ByteArrayInputStream(Base64.getDecoder().decode(p.readValueAs(String.class)));
         ObjectInputStream ois = new ObjectInputStream(bais)) {
        return (SimpleSession) ois.readObject();
    } catch (ClassNotFoundException e) {
        ctxt.reportInputMismatch(SimpleSession.class, "failed to deserialize a session: " + e);
        throw new Error(); // Should never reach here
    }
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:12,代碼來源:SimpleSessionJsonDeserializer.java

示例3: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //導入方法依賴的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

示例4: fail

import com.fasterxml.jackson.databind.DeserializationContext; //導入方法依賴的package包/類
private static ServerPort fail(DeserializationContext ctx, JsonNode root) throws JsonMappingException {
    ctx.reportInputMismatch(ServerPort.class, "invalid server port information: %s", root);
    throw new Error(); // Should never reach here.
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:5,代碼來源:CentralDogmaConfig.java

示例5: deserialize

import com.fasterxml.jackson.databind.DeserializationContext; //導入方法依賴的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


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