本文整理匯總了Java中com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException類的典型用法代碼示例。如果您正苦於以下問題:Java UnrecognizedPropertyException類的具體用法?Java UnrecognizedPropertyException怎麽用?Java UnrecognizedPropertyException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UnrecognizedPropertyException類屬於com.fasterxml.jackson.databind.exc包,在下文中一共展示了UnrecognizedPropertyException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleHttpMessageNotReadableException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public XAPIErrorInfo handleHttpMessageNotReadableException(final HttpServletRequest request, HttpMessageNotReadableException e) {
if (e.getCause() instanceof UnrecognizedPropertyException) {
return this.handleUnrecognizedPropertyException(request, (UnrecognizedPropertyException)e.getCause());
} else {
XAPIErrorInfo result;
if (e.getCause() instanceof JsonProcessingException) {
final JsonProcessingException jpe = (JsonProcessingException)e.getCause();
result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, jpe.getOriginalMessage());
} else {
result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, e);
}
this.logException(e);
this.logError(result);
return result;
}
}
開發者ID:Apereo-Learning-Analytics-Initiative,項目名稱:OpenLRW,代碼行數:20,代碼來源:XAPIExceptionHandlerAdvice.java
示例2: handleInputNotReadableException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的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();
}
示例3: handle
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@ExceptionHandler(value = { HttpMessageNotReadableException.class, UnrecognizedPropertyException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
@Override
public MessageResource handle(final Exception e) throws Exception {
LOGGER.error("Handling message not readable exception", e);
MessageResource messageResource = new MessageResource(MessageType.ERROR, e.getMessage());
BaseExceptionHandler exceptionHandler = handlers.get(e.getCause() != null ? e.getCause().getClass().getName() : "");
if (exceptionHandler != null) {
messageResource = exceptionHandler.handle(e.getCause());
}
return messageResource;
}
示例4: testHandleWithHanglersExceptionHandler
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Test
public void testHandleWithHanglersExceptionHandler() throws Exception {
// Given
String msg = "msg";
HttpMessageNotReadableException e = new HttpMessageNotReadableException(msg, new UnrecognizedPropertyException(null, null, null, null, null));
MessageResource expected = new MessageResource(MessageType.ERROR, e.getMessage());
// When
when(handlers.get(anyString())).thenReturn(exceptionHandler);
when(exceptionHandler.handle(Matchers.<Throwable>any())).thenReturn(expected);
MessageResource actual = unit.handle(e);
// Then
verify(handlers).get(e.getCause().getClass().getName());
verify(exceptionHandler).handle(e.getCause());
assertEquals(expected, actual);
}
示例5: testHandle
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Test
public void testHandle() throws Exception {
// Given
JsonLocation loc = new JsonLocation(null, 1L, 1, 1, 1);
Class<?> clz = UnrecognizedPropertyException.class;
Collection<Object> fields = Arrays.asList("field1", "field2");
String propName = "propName";
String message = "message";
UnrecognizedPropertyException e = new UnrecognizedPropertyException(message, loc, clz, propName, fields);
MessageResource expected = new UnrecognizedPropertyMessageResource(MessageType.ERROR, "Unrecognized Property sent", propName, fields.stream().map(field -> field.toString()).collect(Collectors.toList()));
// When
MessageResource actual = unit.handle(e);
// Then
assertEquals(expected, actual);
}
示例6: resolveHttpMessageNotReadableException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ErrorResponse> resolveHttpMessageNotReadableException(HttpServletRequest request, HttpMessageNotReadableException ex) {
StringBuilder description = new StringBuilder();
List<ClientError> clientErrors = Lists.newArrayList();
description.append("Could not read document.");
if (ex.getRootCause() instanceof JsonParseException) {
description.append(" Json parse not possible.").append(ex.getRootCause().getMessage());
} else if (ex.getMessage().startsWith("Required request body is missing")) {
description.append(" Missing request body.");
}
else if (ex.getRootCause() instanceof UnrecognizedPropertyException) {
description.append(" Unrecognized property");
clientErrors.add(ClientError.fromUnrecognizedPropertyException((UnrecognizedPropertyException) ex.getCause()));
}
return LoggableErrorResponseCreator.create(HttpStatus.BAD_REQUEST)
.withDescription(description.toString())
.withClientErrors(clientErrors)
.log()
.createErrorResponse();
}
示例7: ignoreWriteonly
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Test
public void ignoreWriteonly() throws Exception {
WriteMany writeMany = new WriteMany();
writeMany.readWrite = 6;
String serialized = Jackson.defaultMapper().writeValueAsString(writeMany);
log.debug("serial writeMany {}", serialized);
// should silently ignore "someInt"
Config passingOverride =
ConfigValueFactory.fromAnyRef(true).atPath("addthis.codec.jackson.ignore.write-only");
Jackson.defaultCodec()
.withOverrides(passingOverride)
.getObjectMapper()
.readValue(serialized, WriteMany.class);
// should error on "someInt"
thrown.expect(UnrecognizedPropertyException.class);
Config erroringOverride =
ConfigValueFactory.fromAnyRef(false).atPath("addthis.codec.jackson.ignore.write-only");
Jackson.defaultCodec()
.withOverrides(erroringOverride)
.getObjectMapper()
.readValue(serialized, WriteMany.class);
}
示例8: createBroadcastMessageWithIncorrectSimplePush
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Test(expected = UnrecognizedPropertyException.class)
public void createBroadcastMessageWithIncorrectSimplePush() throws IOException {
final Map<String, Object> container = new LinkedHashMap<>();
final Map<String, Object> messageObject = new LinkedHashMap<>();
messageObject.put("alert", "Howdy");
messageObject.put("sound", "default");
messageObject.put("badge", 2);
Map<String, String> data = new HashMap<>();
data.put("someKey", "someValue");
messageObject.put("user-data", data);
container.put("message", messageObject);
messageObject.put("simplePush", "version=123");
// parse it:
parsePushMessage(container);
}
示例9: from
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
public static Error from(JsonMappingException e) {
String path = e.getPath().stream().map(x -> x.getFieldName()).collect(Collectors.joining(" -> "));
if (e instanceof InvalidFormatException) {
InvalidFormatException ex = (InvalidFormatException) e;
return new Error(
String.format("Invalid value for %s. Expected value of type %s but got: '%s'", path, ex.getTargetType().getSimpleName(), ex.getValue()),
e
);
} else if (e instanceof IgnoredPropertyException) {
return new Error(String.format("Missing value for %s", path), e);
} else if (e instanceof UnrecognizedPropertyException) {
return new Error(String.format("Unknown property: %s", path), e);
} else {
return new Error(String.format("Cannot parse JSON data for property %s", path), e);
}
}
示例10: handleHttpMessageNotReadableException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public XApiErrorInfo handleHttpMessageNotReadableException(final HttpServletRequest request, HttpMessageNotReadableException e) {
if (e.getCause() instanceof UnrecognizedPropertyException) {
return this.handleUnrecognizedPropertyException(request, (UnrecognizedPropertyException)e.getCause());
} else {
XApiErrorInfo result;
if (e.getCause() instanceof JsonProcessingException) {
final JsonProcessingException jpe = (JsonProcessingException)e.getCause();
result = new XApiErrorInfo(HttpStatus.BAD_REQUEST, request, jpe.getOriginalMessage());
} else {
result = new XApiErrorInfo(HttpStatus.BAD_REQUEST, request, e);
}
this.logException(e);
this.logError(result);
return result;
}
}
開發者ID:Apereo-Learning-Analytics-Initiative,項目名稱:OpenLRS,代碼行數:20,代碼來源:XApiExceptionHandlerAdvice.java
示例11: toResponse
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Override
public Response toResponse(UnrecognizedPropertyException ex) {
return ResultStash.builder()
.setStatus(Response.Status.PRECONDITION_FAILED)
.addFieldError("Unknown JSON field detected.", "unknown.json.field", MapperUtils.printPropertyPath(ex), "")
.buildResponse();
}
示例12: handleExceptionDuringLoading
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
/**
* Handles exception during loading.
* Most exceptions are logged and re-thrown as {@link ConfigurationException}
* @param e
*/
private void handleExceptionDuringLoading(IOException e) {
if (e instanceof UnrecognizedPropertyException) {
LOGGER.warn("Read an unexpected property. Ignoring it.", e);
} else if (e instanceof JsonParseException) {
throw LOGGER.throwing(Level.ERROR, new ConfigurationException("The config file could not be parsed", e));
} else if (e instanceof JsonMappingException) {
throw LOGGER.throwing(Level.ERROR, new ConfigurationException("The config object is corrupt.", e));
} else {
throw LOGGER.throwing(Level.ERROR, new ConfigurationException("An error occurred while reading the configuration.", e));
}
}
示例13: toResponse
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Override
public Response toResponse(JsonMappingException exception) {
if(exception instanceof UnrecognizedPropertyException) {
return buildResponse(BAD_REQUEST, "Unrecognized property.", Collections.singletonMap("property_name", ((UnrecognizedPropertyException) exception).getPropertyName()));
}
return buildResponse(BAD_REQUEST, "Mapping error - Some fields are missing.");
}
示例14: handleUnrecognizedPropertyException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@ExceptionHandler(UnrecognizedPropertyException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public XAPIErrorInfo handleUnrecognizedPropertyException(final HttpServletRequest request, UnrecognizedPropertyException e) {
final String errorMessage = String.format("Unrecognized property: [%s].", e.getPropertyName());
final XAPIErrorInfo result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, errorMessage);
this.logException(e);
this.logError(result);
return result;
}
開發者ID:Apereo-Learning-Analytics-Initiative,項目名稱:OpenLRW,代碼行數:11,代碼來源:XAPIExceptionHandlerAdvice.java
示例15: testUnrecognizedPropertyException
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; //導入依賴的package包/類
@Test
public void testUnrecognizedPropertyException() {
final UnrecognizedPropertyException format = new UnrecognizedPropertyException(null, "", null, String.class, "property",
Collections.emptyList());
format.prependPath(null, "property");
format.prependPath("property", "property2");
final ValidationJsonException validationJsonException = new ValidationJsonException(format);
Assert.assertFalse(validationJsonException.getErrors().isEmpty());
Assert.assertEquals("{property2.property=[{rule=Mapping}]}", validationJsonException.getErrors().toString());
}