Java Code Examples for com.fasterxml.jackson.databind.JsonMappingException#getMessage()

The following examples show how to use com.fasterxml.jackson.databind.JsonMappingException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRequestHandler.java    From BlogService_SparkExample with MIT License 6 votes vote down vote up
@Override
public Object handle(Request request, Response response) throws Exception {
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        V value = null;
        if (valueClass != EmptyPayload.class) {
            value = objectMapper.readValue(request.body(), valueClass);
        }
        Map<String, String> urlParams = request.params();
        Answer answer = process(value, urlParams, shouldReturnHtml(request));
        response.status(answer.getCode());
        if (shouldReturnHtml(request)) {
            response.type("text/html");
        } else {
            response.type("application/json");
        }
        response.body(answer.getBody());
        return answer.getBody();
    } catch (JsonMappingException e) {
        response.status(400);
        response.body(e.getMessage());
        return e.getMessage();
    }
}
 
Example 2
Source File: Bootloader.java    From crazyflie-android-client with GNU General Public License v2.0 5 votes vote down vote up
public static Manifest readManifest (File file) throws IOException {
    String errorMessage = "";
    try {
        return mMapper.readValue(file, Manifest.class);
    } catch (JsonParseException jpe) {
        errorMessage = jpe.getMessage();
    } catch (JsonMappingException jme) {
        errorMessage = jme.getMessage();
    }
    LoggerFactory.getLogger("Bootloader").error("Error while parsing manifest " + file.getName() + ": " + errorMessage);
    return null;
}
 
Example 3
Source File: Bootloader.java    From crazyflie-android-client with GNU General Public License v2.0 5 votes vote down vote up
public static void writeManifest (String fileName, Manifest manifest) throws IOException {
    String errorMessage = "";
    mMapper.enable(SerializationFeature.INDENT_OUTPUT);
    try {
        mMapper.writeValue(new File(fileName), manifest);
        return;
    } catch (JsonGenerationException jge) {
        errorMessage = jge.getMessage();
    } catch (JsonMappingException jme) {
        errorMessage = jme.getMessage();
    }
    LoggerFactory.getLogger("Bootloader").error("Could not save manifest to file " + fileName + ".\n" + errorMessage);
}
 
Example 4
Source File: SimpleCreate.java    From elepy with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(HttpContext context, ModelContext<T> modelContext) throws Exception {

    try {

        var objectMapper = context.elepy().objectMapper();
        String body = context.request().body();

        T item = objectMapper.readValue(body, modelContext.getModelType());

        beforeCreate(item, context.request(), modelContext.getCrud());

        super.singleCreate(context, item, modelContext.getCrud(), modelContext);

        afterCreate(item, modelContext.getCrud());
        context.response().status(200);
        context.response().result(Message.of("Successfully created item", 200).withProperty("createdRecords", List.of(item)));

    } catch (JsonMappingException e) {
        throw new ElepyException("Error mapping SimpleCreate: " + e.getMessage());
    }
}