当前位置: 首页>>代码示例>>Java>>正文


Java InvalidTypeIdException类代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.exc.InvalidTypeIdException的典型用法代码示例。如果您正苦于以下问题:Java InvalidTypeIdException类的具体用法?Java InvalidTypeIdException怎么用?Java InvalidTypeIdException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InvalidTypeIdException类属于com.fasterxml.jackson.databind.exc包,在下文中一共展示了InvalidTypeIdException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleInputNotReadableException

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; //导入依赖的package包/类
@ExceptionHandler({HttpMessageNotReadableException.class, InvalidJsonException.class, InvalidFormatException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ResponseError handleInputNotReadableException(Exception exception) {
  final Throwable cause = exception.getCause() == null ? exception : exception.getCause();
  if (cause instanceof UnrecognizedPropertyException) {
    return constructError("error.invalid_json_key", ((UnrecognizedPropertyException) cause).getPropertyName());
  } else if (cause instanceof InvalidTypeIdException
      || (cause instanceof JsonMappingException && cause.getMessage()
      .contains("missing property 'type'"))) {
    return constructError("error.invalid_type_with_set_prompt");
  } else if (cause instanceof InvalidFormatException) {
    for (InvalidFormatException.Reference reference : ((InvalidFormatException) cause)
        .getPath()) {
      if ("operations".equals(reference.getFieldName())) {
        return constructError("error.permission.invalid_operation");
      }
    }
  }
  return badRequestResponse();
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:21,代码来源:ExceptionHandlers.java

示例2: implementDeserializeMethod

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; //导入依赖的package包/类
@Override
protected MethodSpec implementDeserializeMethod(TypeElement typeElement, Builder deserializeMethodBuilder) {
    Optional<DeserializationConstructs> constructs = loadConstructs(typeElement);
    if (!constructs.isPresent()) {
        return deserializeMethodBuilder.addStatement("return null").build();
    }

    TypeElement enumTypeElement = constructs.get().getEnumTypeElement();
    ImmutableList<Element> enumValueElements = constructs.get().getEnumValueElements();
    ExecutableElement enumValueAccessorMethod = constructs.get().getEnumValueAccessorMethod();
    ExecutableElement enumInstanceAccessorMethod = constructs.get().getEnumInstanceAccessorMethod();

    String memberVariableName = this.processorUtil.createMemberVariableName(enumValueAccessorMethod);

    deserializeMethodBuilder.addStatement("$T codec = $L.getCodec()", ObjectCodec.class, JSON_PARSER_PARAMETER_NAME)
            .addStatement("$T rootNode = codec.readTree($L)", JsonNode.class, JSON_PARSER_PARAMETER_NAME)
            .addStatement("$T typeNode = rootNode.get($S)", JsonNode.class, memberVariableName)
            .beginControlFlow("if (typeNode == null)")
            .addStatement("$T javaType = $L.constructType($T.class)", JavaType.class, DESERIALIZATION_CONTEXT_PARAMETER_NAME, enumTypeElement)
            .addStatement("throw new $T($L, \"$L not present\", javaType, null)", InvalidTypeIdException.class, JSON_PARSER_PARAMETER_NAME, memberVariableName)
            .endControlFlow()
            .addStatement("$T type = codec.treeToValue(typeNode, $T.$L)", enumTypeElement, enumTypeElement, "class")
            .beginControlFlow("switch (type)");

    enumValueElements.forEach(enumValueElement -> deserializeMethodBuilder
            .beginControlFlow("case $L:", enumValueElement)
            .addStatement("return codec.treeToValue(rootNode, $T.$L.$L)", enumTypeElement, enumValueElement, enumInstanceAccessorMethod)
            .endControlFlow());

    return deserializeMethodBuilder.beginControlFlow("default :")
            .addStatement("return null")
            .endControlFlow()
            .endControlFlow()
            .build();
}
 
开发者ID:peckb1,项目名称:autojackson,代码行数:36,代码来源:ComplexDeserializerCreator.java

示例3: typeFromId

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; //导入依赖的package包/类
@Override
public JavaType typeFromId(DatabindContext context, String id) throws IOException {
  Class<?> subType;
  id = id.toLowerCase();

  switch (id) {
    case CertificateCredentialVersionData.CREDENTIAL_TYPE:
      subType = CertificateSetRequest.class;
      break;
    case ValueCredentialVersionData.CREDENTIAL_TYPE:
      subType = ValueSetRequest.class;
      break;
    case JsonCredentialVersionData.CREDENTIAL_TYPE:
      subType = JsonSetRequest.class;
      break;
    case PasswordCredentialVersionData.CREDENTIAL_TYPE:
      subType = PasswordSetRequest.class;
      break;
    case RsaCredentialVersionData.CREDENTIAL_TYPE:
      subType = RsaSetRequest.class;
      break;
    case SshCredentialVersionData.CREDENTIAL_TYPE:
      subType = SshSetRequest.class;
      break;
    case UserCredentialVersionData.CREDENTIAL_TYPE:
      subType = UserSetRequest.class;
      break;
    default:
      String message = String.format("Could not resolve type id '%s' into a subtype of %s", id, baseType);
      throw new InvalidTypeIdException(null, message, baseType, id);
  }

  return context.constructSpecializedType(baseType, subType);
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:35,代码来源:SetRequestTypeIdResolver.java

示例4: whenTypeIsEmptyString_throwsException

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; //导入依赖的package包/类
@Test(expected = InvalidTypeIdException.class)
public void whenTypeIsEmptyString_throwsException() throws IOException {
  String json = "{" +
      "\"name\":\"some-name\"," +
      "\"type\":\"\"," +
      "\"value\":\"some-value\"," +
      "\"overwrite\":true" +
      "}";

  JsonTestHelper.deserializeChecked(json, BaseCredentialSetRequest.class);
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:12,代码来源:BaseCredentialSetRequestTest.java

示例5: whenTypeIsUnknown_throwsException

import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; //导入依赖的package包/类
@Test(expected = InvalidTypeIdException.class)
public void whenTypeIsUnknown_throwsException() throws IOException {
  String json = "{" +
      "\"name\":\"some-name\"," +
      "\"type\":\"moose\"," +
      "\"value\":\"some-value\"," +
      "\"overwrite\":true" +
      "}";

  JsonTestHelper.deserializeChecked(json, BaseCredentialSetRequest.class);
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:12,代码来源:BaseCredentialSetRequestTest.java


注:本文中的com.fasterxml.jackson.databind.exc.InvalidTypeIdException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。