Skip to content

Commit

Permalink
Minor improvements to error reporting, related to work on #691
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 7, 2015
1 parent 186b89d commit 960e49e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public void serializeWithType(T value, JsonGenerator gen, SerializerProvider ser
if (clz == null) {
clz = value.getClass();
}
throw new UnsupportedOperationException("Type id handling not implemented for type "+clz.getName());
throw serializers.mappingException("Type id handling not implemented for type %s (by serializer of type %s)",
clz.getName(), getClass().getName());
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ public JsonSerializer<?> handleSecondaryContextualization(JsonSerializer<?> ser,

/*
/********************************************************
/* Convenience methods
/* Convenience methods for serializing using default methods
/********************************************************
*/

Expand All @@ -919,8 +919,7 @@ public JsonSerializer<?> handleSecondaryContextualization(JsonSerializer<?> ser,
* field values are best handled calling
* {@link #defaultSerializeField} instead.
*/
public final void defaultSerializeValue(Object value, JsonGenerator jgen)
throws IOException, JsonProcessingException
public final void defaultSerializeValue(Object value, JsonGenerator jgen) throws IOException
{
if (value == null) {
if (_stdNullValueSerializer) { // minor perf optimization
Expand All @@ -940,7 +939,7 @@ public final void defaultSerializeValue(Object value, JsonGenerator jgen)
* null) using standard serializer locating functionality.
*/
public final void defaultSerializeField(String fieldName, Object value, JsonGenerator jgen)
throws IOException, JsonProcessingException
throws IOException
{
jgen.writeFieldName(fieldName);
if (value == null) {
Expand All @@ -958,12 +957,6 @@ public final void defaultSerializeField(String fieldName, Object value, JsonGene
}
}

/*
/**********************************************************
/* Convenience methods
/**********************************************************
*/

/**
* Method that will handle serialization of Date(-like) values, using
* {@link SerializationConfig} settings to determine expected serialization
Expand All @@ -972,7 +965,7 @@ public final void defaultSerializeField(String fieldName, Object value, JsonGene
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
throws IOException, JsonProcessingException
throws IOException
{
// [JACKSON-87]: Support both numeric timestamps and textual
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
Expand All @@ -990,7 +983,7 @@ public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(Date date, JsonGenerator jgen)
throws IOException, JsonProcessingException
throws IOException
{
// [JACKSON-87]: Support both numeric timestamps and textual
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
Expand All @@ -1006,7 +999,7 @@ public final void defaultSerializeDateValue(Date date, JsonGenerator jgen)
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(long timestamp, JsonGenerator jgen)
throws IOException, JsonProcessingException
throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
jgen.writeFieldName(String.valueOf(timestamp));
Expand All @@ -1020,18 +1013,16 @@ public void defaultSerializeDateKey(long timestamp, JsonGenerator jgen)
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(Date date, JsonGenerator jgen)
throws IOException, JsonProcessingException
public void defaultSerializeDateKey(Date date, JsonGenerator jgen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
jgen.writeFieldName(String.valueOf(date.getTime()));
} else {
jgen.writeFieldName(_dateFormat().format(date));
}
}

public final void defaultSerializeNull(JsonGenerator jgen)
throws IOException, JsonProcessingException

public final void defaultSerializeNull(JsonGenerator jgen) throws IOException
{
if (_stdNullValueSerializer) { // minor perf optimization
jgen.writeNull();
Expand All @@ -1040,12 +1031,28 @@ public final void defaultSerializeNull(JsonGenerator jgen)
}
}

/*
/********************************************************
/* Error reporting
/********************************************************
*/

/**
* @since 2.6
*/
public JsonMappingException mappingException(String message, Object... args) {
if (args != null && args.length > 0) {
message = String.format(message, args);
}
return new JsonMappingException(message);
}

/*
/********************************************************
/* Helper methods
/********************************************************
*/

protected void _reportIncompatibleRootType(Object value, JavaType rootType)
throws IOException, JsonProcessingException
{
Expand Down Expand Up @@ -1099,7 +1106,7 @@ protected JsonSerializer<Object> _findExplicitUntypedSerializer(Class<?> runtime
/* serializers
/**********************************************************
*/

/**
* Method that will try to construct a value serializer; and if
* one is successfully created, cache it for reuse.
Expand Down

0 comments on commit 960e49e

Please sign in to comment.