Untitled

                Never    
Java
       
// goal: to add custom message in case of error, not get rid of exception itself

// main exception, whicn need to get through to UI with custom message:
Caused by: com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
	at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1961)
	at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:188)

// final catch of exception after which it ignored
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Can not write a field name, expecting a value; nested exception is com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:296)


// endpoint in the controller
// exception happens when we try to serialize SettingsObject into json 
    @RequestMapping(value = "", method = RequestMethod.GET)
    public Wrapper<SettingsObject> getConfig(HttpServletRequest request)

// 
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@JsonSerialize(using = WrapperSerializer.class)
@JsonDeserialize(using = WrapperDeserializer.class)
public class Wrapper<V>

Raw Text