allow chef to extend this

This commit is contained in:
Adrian Cole 2012-04-16 11:08:36 -07:00
parent cedd906bdb
commit 9267ac29ba
1 changed files with 7 additions and 3 deletions

View File

@ -72,7 +72,7 @@ public abstract class NullHackJsonLiteralAdapter<L> extends TypeAdapter<L> {
try { try {
// we are using an implementation hack which depends on replacing null with the raw json // we are using an implementation hack which depends on replacing null with the raw json
// supplied as a parameter. In this case, we must ensure we indeed serialize nulls. // supplied as a parameter. In this case, we must ensure we indeed serialize nulls.
NullReplacingWriter nullReplacingWriter = new NullReplacingWriter(writer, value.toString()); NullReplacingWriter nullReplacingWriter = new NullReplacingWriter(writer, toString(value));
setWriter(jsonWriter, nullReplacingWriter); setWriter(jsonWriter, nullReplacingWriter);
jsonWriter.setSerializeNulls(true); jsonWriter.setSerializeNulls(true);
jsonWriter.nullValue(); jsonWriter.nullValue();
@ -83,7 +83,11 @@ public abstract class NullHackJsonLiteralAdapter<L> extends TypeAdapter<L> {
} }
private Writer getWriter(JsonWriter arg0) { protected String toString(L value) {
return value.toString();
}
protected Writer getWriter(JsonWriter arg0) {
try { try {
return Writer.class.cast(outField.get(arg0)); return Writer.class.cast(outField.get(arg0));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -99,7 +103,7 @@ public abstract class NullHackJsonLiteralAdapter<L> extends TypeAdapter<L> {
} }
} }
private final class NullReplacingWriter extends Writer { public final class NullReplacingWriter extends Writer {
private final Writer delegate; private final Writer delegate;
private final String nullReplacement; private final String nullReplacement;