dump object to String with Jackson

To serialize with Jackson:

public String serialize(Object obj, boolean pretty) {
    ObjectMapper mapper = new ObjectMapper();

    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    if (pretty) {
        return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
    }

    return mapper.writeValueAsString(obj);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)