Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 29, 2017
1 parent c07b0ef commit b90088c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 87 deletions.
Expand Up @@ -31,35 +31,35 @@ public AsExistingPropertyTypeSerializer forProperty(BeanProperty prop) {
public As getTypeInclusion() { return As.EXISTING_PROPERTY; } public As getTypeInclusion() { return As.EXISTING_PROPERTY; }


@Override @Override
public void writeTypePrefixForObject(Object value, JsonGenerator gen) throws IOException public void writeTypePrefixForObject(Object value, JsonGenerator g) throws IOException
{ {
if (gen.canWriteTypeId()) { // only write explicitly if native type id if (g.canWriteTypeId()) { // only write explicitly if native type id
final String typeId = idFromValue(value); final String typeId = idFromValue(value);
if (typeId != null) { if (typeId != null) {
gen.writeTypeId(typeId); g.writeTypeId(typeId);
} }
} }
gen.writeStartObject(); g.writeStartObject();
} }


@Override @Override
public void writeTypePrefixForObject(Object value, JsonGenerator gen, Class<?> type) throws IOException public void writeTypePrefixForObject(Object value, JsonGenerator g, Class<?> type) throws IOException
{ {
if (gen.canWriteTypeId()) { // only write explicitly if native type id if (g.canWriteTypeId()) { // only write explicitly if native type id
final String typeId = idFromValueAndType(value, type); final String typeId = idFromValueAndType(value, type);
if (typeId != null) { if (typeId != null) {
gen.writeTypeId(typeId); g.writeTypeId(typeId);
} }
} }
gen.writeStartObject(); g.writeStartObject();
} }


@Override @Override
public void writeCustomTypePrefixForObject(Object value, JsonGenerator gen, String typeId) throws IOException public void writeCustomTypePrefixForObject(Object value, JsonGenerator g, String typeId) throws IOException
{ {
if ((typeId != null) && gen.canWriteTypeId()) { if ((typeId != null) && g.canWriteTypeId()) {
gen.writeTypeId(typeId); g.writeTypeId(typeId);
} }
gen.writeStartObject(); g.writeStartObject();
} }
} }
Expand Up @@ -48,33 +48,33 @@ public AsExternalTypeSerializer forProperty(BeanProperty prop) {
*/ */


@Override @Override
public void writeTypePrefixForObject(Object value, JsonGenerator gen) throws IOException { public void writeTypePrefixForObject(Object value, JsonGenerator g) throws IOException {
_writeObjectPrefix(value, gen); _writeObjectPrefix(value, g);
} }


@Override @Override
public void writeTypePrefixForObject(Object value, JsonGenerator gen, Class<?> type) throws IOException { public void writeTypePrefixForObject(Object value, JsonGenerator g, Class<?> type) throws IOException {
_writeObjectPrefix(value, gen); _writeObjectPrefix(value, g);
} }


@Override @Override
public void writeTypePrefixForArray(Object value, JsonGenerator gen) throws IOException { public void writeTypePrefixForArray(Object value, JsonGenerator g) throws IOException {
_writeArrayPrefix(value, gen); _writeArrayPrefix(value, g);
} }


@Override @Override
public void writeTypePrefixForArray(Object value, JsonGenerator gen, Class<?> type) throws IOException { public void writeTypePrefixForArray(Object value, JsonGenerator g, Class<?> type) throws IOException {
_writeArrayPrefix(value, gen); _writeArrayPrefix(value, g);
} }


@Override @Override
public void writeTypePrefixForScalar(Object value, JsonGenerator gen) throws IOException { public void writeTypePrefixForScalar(Object value, JsonGenerator g) throws IOException {
_writeScalarPrefix(value, gen); _writeScalarPrefix(value, g);
} }


@Override @Override
public void writeTypePrefixForScalar(Object value, JsonGenerator gen, Class<?> type) throws IOException { public void writeTypePrefixForScalar(Object value, JsonGenerator g, Class<?> type) throws IOException {
_writeScalarPrefix(value, gen); _writeScalarPrefix(value, g);
} }


/* /*
Expand All @@ -84,18 +84,18 @@ public void writeTypePrefixForScalar(Object value, JsonGenerator gen, Class<?> t
*/ */


@Override @Override
public void writeTypeSuffixForObject(Object value, JsonGenerator gen) throws IOException { public void writeTypeSuffixForObject(Object value, JsonGenerator g) throws IOException {
_writeObjectSuffix(value, gen, idFromValue(value)); _writeObjectSuffix(value, g, idFromValue(value));
} }


@Override @Override
public void writeTypeSuffixForArray(Object value, JsonGenerator gen) throws IOException { public void writeTypeSuffixForArray(Object value, JsonGenerator g) throws IOException {
_writeArraySuffix(value, gen, idFromValue(value)); _writeArraySuffix(value, g, idFromValue(value));
} }


@Override @Override
public void writeTypeSuffixForScalar(Object value, JsonGenerator gen) throws IOException { public void writeTypeSuffixForScalar(Object value, JsonGenerator g) throws IOException {
_writeScalarSuffix(value, gen, idFromValue(value)); _writeScalarSuffix(value, g, idFromValue(value));
} }


/* /*
Expand All @@ -105,33 +105,33 @@ public void writeTypeSuffixForScalar(Object value, JsonGenerator gen) throws IOE
*/ */


@Override @Override
public void writeCustomTypePrefixForScalar(Object value, JsonGenerator gen, String typeId) throws IOException { public void writeCustomTypePrefixForScalar(Object value, JsonGenerator g, String typeId) throws IOException {
_writeScalarPrefix(value, gen); _writeScalarPrefix(value, g);
} }


@Override @Override
public void writeCustomTypePrefixForObject(Object value, JsonGenerator gen, String typeId) throws IOException { public void writeCustomTypePrefixForObject(Object value, JsonGenerator g, String typeId) throws IOException {
_writeObjectPrefix(value, gen); _writeObjectPrefix(value, g);
} }


@Override @Override
public void writeCustomTypePrefixForArray(Object value, JsonGenerator gen, String typeId) throws IOException { public void writeCustomTypePrefixForArray(Object value, JsonGenerator g, String typeId) throws IOException {
_writeArrayPrefix(value, gen); _writeArrayPrefix(value, g);
} }


@Override @Override
public void writeCustomTypeSuffixForScalar(Object value, JsonGenerator gen, String typeId) throws IOException { public void writeCustomTypeSuffixForScalar(Object value, JsonGenerator g, String typeId) throws IOException {
_writeScalarSuffix(value, gen, typeId); _writeScalarSuffix(value, g, typeId);
} }


@Override @Override
public void writeCustomTypeSuffixForObject(Object value, JsonGenerator gen, String typeId) throws IOException { public void writeCustomTypeSuffixForObject(Object value, JsonGenerator g, String typeId) throws IOException {
_writeObjectSuffix(value, gen, typeId); _writeObjectSuffix(value, g, typeId);
} }


@Override @Override
public void writeCustomTypeSuffixForArray(Object value, JsonGenerator gen, String typeId) throws IOException { public void writeCustomTypeSuffixForArray(Object value, JsonGenerator g, String typeId) throws IOException {
_writeArraySuffix(value, gen, typeId); _writeArraySuffix(value, g, typeId);
} }


/* /*
Expand All @@ -141,33 +141,33 @@ public void writeCustomTypeSuffixForArray(Object value, JsonGenerator gen, Strin
*/ */


// nothing to wrap it with: // nothing to wrap it with:
protected final void _writeScalarPrefix(Object value, JsonGenerator gen) throws IOException { } protected final void _writeScalarPrefix(Object value, JsonGenerator g) throws IOException { }


protected final void _writeObjectPrefix(Object value, JsonGenerator gen) throws IOException { protected final void _writeObjectPrefix(Object value, JsonGenerator g) throws IOException {
gen.writeStartObject(); g.writeStartObject();
} }


protected final void _writeArrayPrefix(Object value, JsonGenerator gen) throws IOException { protected final void _writeArrayPrefix(Object value, JsonGenerator g) throws IOException {
gen.writeStartArray(); g.writeStartArray();
} }


protected final void _writeScalarSuffix(Object value, JsonGenerator gen, String typeId) throws IOException { protected final void _writeScalarSuffix(Object value, JsonGenerator g, String typeId) throws IOException {
if (typeId != null) { if (typeId != null) {
gen.writeStringField(_typePropertyName, typeId); g.writeStringField(_typePropertyName, typeId);
} }
} }


protected final void _writeObjectSuffix(Object value, JsonGenerator gen, String typeId) throws IOException { protected final void _writeObjectSuffix(Object value, JsonGenerator g, String typeId) throws IOException {
gen.writeEndObject(); g.writeEndObject();
if (typeId != null) { if (typeId != null) {
gen.writeStringField(_typePropertyName, typeId); g.writeStringField(_typePropertyName, typeId);
} }
} }


protected final void _writeArraySuffix(Object value, JsonGenerator gen, String typeId) throws IOException { protected final void _writeArraySuffix(Object value, JsonGenerator g, String typeId) throws IOException {
gen.writeEndArray(); g.writeEndArray();
if (typeId != null) { if (typeId != null) {
gen.writeStringField(_typePropertyName, typeId); g.writeStringField(_typePropertyName, typeId);
} }
} }
} }
Expand Up @@ -28,7 +28,8 @@ public AsPropertyTypeSerializer(TypeIdResolver idRes, BeanProperty property, Str


@Override @Override
public AsPropertyTypeSerializer forProperty(BeanProperty prop) { public AsPropertyTypeSerializer forProperty(BeanProperty prop) {
return (_property == prop) ? this : new AsPropertyTypeSerializer(this._idResolver, prop, this._typePropertyName); return (_property == prop) ? this :
new AsPropertyTypeSerializer(this._idResolver, prop, this._typePropertyName);
} }


@Override @Override
Expand All @@ -38,48 +39,48 @@ public AsPropertyTypeSerializer forProperty(BeanProperty prop) {
public As getTypeInclusion() { return As.PROPERTY; } public As getTypeInclusion() { return As.PROPERTY; }


@Override @Override
public void writeTypePrefixForObject(Object value, JsonGenerator jgen) throws IOException public void writeTypePrefixForObject(Object value, JsonGenerator g) throws IOException
{ {
final String typeId = idFromValue(value); final String typeId = idFromValue(value);
if (typeId == null) { if (typeId == null) {
jgen.writeStartObject(); g.writeStartObject();
} else if (jgen.canWriteTypeId()) { } else if (g.canWriteTypeId()) {
jgen.writeTypeId(typeId); g.writeTypeId(typeId);
jgen.writeStartObject(); g.writeStartObject();
} else { } else {
jgen.writeStartObject(); g.writeStartObject();
jgen.writeStringField(_typePropertyName, typeId); g.writeStringField(_typePropertyName, typeId);
} }
} }


@Override @Override
public void writeTypePrefixForObject(Object value, JsonGenerator jgen, Class<?> type) throws IOException public void writeTypePrefixForObject(Object value, JsonGenerator g, Class<?> type) throws IOException
{ {
final String typeId = idFromValueAndType(value, type); final String typeId = idFromValueAndType(value, type);
if (typeId == null) { if (typeId == null) {
jgen.writeStartObject(); g.writeStartObject();
} else if (jgen.canWriteTypeId()) { } else if (g.canWriteTypeId()) {
jgen.writeTypeId(typeId); g.writeTypeId(typeId);
jgen.writeStartObject(); g.writeStartObject();
} else { } else {
jgen.writeStartObject(); g.writeStartObject();
jgen.writeStringField(_typePropertyName, typeId); g.writeStringField(_typePropertyName, typeId);
} }
} }


//public void writeTypePrefixForArray(Object value, JsonGenerator jgen) //public void writeTypePrefixForArray(Object value, JsonGenerator g)
//public void writeTypePrefixForArray(Object value, JsonGenerator jgen, Class<?> type) //public void writeTypePrefixForArray(Object value, JsonGenerator g, Class<?> type)
//public void writeTypePrefixForScalar(Object value, JsonGenerator jgen) //public void writeTypePrefixForScalar(Object value, JsonGenerator g)
//public void writeTypePrefixForScalar(Object value, JsonGenerator jgen, Class<?> type) //public void writeTypePrefixForScalar(Object value, JsonGenerator g, Class<?> type)


@Override @Override
public void writeTypeSuffixForObject(Object value, JsonGenerator jgen) throws IOException { public void writeTypeSuffixForObject(Object value, JsonGenerator g) throws IOException {
// always need to close, regardless of whether its native type id or not // always need to close, regardless of whether its native type id or not
jgen.writeEndObject(); g.writeEndObject();
} }


//public void writeTypeSuffixForArray(Object value, JsonGenerator jgen) //public void writeTypeSuffixForArray(Object value, JsonGenerator g)
//public void writeTypeSuffixForScalar(Object value, JsonGenerator jgen) //public void writeTypeSuffixForScalar(Object value, JsonGenerator g)




/* /*
Expand All @@ -91,21 +92,21 @@ public void writeTypeSuffixForObject(Object value, JsonGenerator jgen) throws IO
// Only need to override Object-variants // Only need to override Object-variants


@Override @Override
public void writeCustomTypePrefixForObject(Object value, JsonGenerator jgen, String typeId) throws IOException public void writeCustomTypePrefixForObject(Object value, JsonGenerator g, String typeId) throws IOException
{ {
if (typeId == null) { if (typeId == null) {
jgen.writeStartObject(); g.writeStartObject();
} else if (jgen.canWriteTypeId()) { } else if (g.canWriteTypeId()) {
jgen.writeTypeId(typeId); g.writeTypeId(typeId);
jgen.writeStartObject(); g.writeStartObject();
} else { } else {
jgen.writeStartObject(); g.writeStartObject();
jgen.writeStringField(_typePropertyName, typeId); g.writeStringField(_typePropertyName, typeId);
} }
} }


@Override @Override
public void writeCustomTypeSuffixForObject(Object value, JsonGenerator jgen, String typeId) throws IOException { public void writeCustomTypeSuffixForObject(Object value, JsonGenerator g, String typeId) throws IOException {
jgen.writeEndObject(); g.writeEndObject();
} }
} }

0 comments on commit b90088c

Please sign in to comment.