@Override public void registerSubtypes(Class<?>... classes) { NamedType[] types = new NamedType[classes.length]; for (int i = 0, len = classes.length; i < len; ++i) { types[i] = new NamedType(classes[i]); } registerSubtypes(types); }
public NamedType(Class<?> c, String name) { _class = c; _hashCode = c.getName().hashCode(); setName(name); }
/** * Method for registering specified class as a subtype, so that * typename-based resolution can link supertypes to subtypes * (as an alternative to using annotations). * Type for given class is determined from appropriate annotation; * or if missing, default name (unqualified class name) * * @since 1.6 */ public void registerSubtypes(Class<?>... classes) { getSubtypeResolver().registerSubtypes(classes); }
@Override public void writeTypePrefixForObject(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { // wrapper jgen.writeStartObject(); // and then JSON Object start caller wants jgen.writeObjectFieldStart(_idResolver.idFromValue(value)); }
@Override public void writeTypePrefixForScalar(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { // only need the wrapper array jgen.writeStartArray(); jgen.writeString(_idResolver.idFromValueAndType(value, type)); }
/** * Method for enabling automatic inclusion of type information, needed * for proper deserialization of polymorphic types (unless types * have been annotated with {@link org.codehaus.jackson.annotate.JsonTypeInfo}). * * @param applicability Defines kinds of types for which additional type information * is added; see {@link DefaultTyping} for more information. */ public ObjectMapper enableDefaultTyping(DefaultTyping applicability, JsonTypeInfo.As includeAs) { TypeResolverBuilder<?> typer = new DefaultTypeResolverBuilder(applicability); // we'll always use full class name, when using defaulting typer = typer.init(JsonTypeInfo.Id.CLASS, null); typer = typer.inclusion(includeAs); return setDefaultTyping(typer); }
protected final void _writeSuffix(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { jgen.writeEndObject(); jgen.writeStringField(_typePropertyName, _idResolver.idFromValue(value)); } }
@Override public void writeTypePrefixForObject(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField(_typePropertyName, _idResolver.idFromValueAndType(value, type)); }
/** * Method for registering specified class as a subtype, so that * typename-based resolution can link supertypes to subtypes * (as an alternative to using annotations). * Name may be provided as part of argument, but if not will * be based on annotations or use default name (unqualified * class name). * * @since 1.6 */ public void registerSubtypes(NamedType... types) { getSubtypeResolver().registerSubtypes(types); }
@Override public void writeTypePrefixForObject(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField(_typePropertyName, _idResolver.idFromValue(value)); }
@Override public void writeTypePrefixForObject(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { // wrapper jgen.writeStartObject(); // and then JSON Object start caller wants jgen.writeObjectFieldStart(_idResolver.idFromValueAndType(value, type)); }
@Override public void writeTypePrefixForArray(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { // can still wrap ok jgen.writeStartObject(); // and then JSON Array start caller wants jgen.writeArrayFieldStart(_idResolver.idFromValue(value)); }
@Override public void writeTypePrefixForArray(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { // can still wrap ok jgen.writeStartObject(); // and then JSON Array start caller wants jgen.writeArrayFieldStart(_idResolver.idFromValueAndType(value, type)); }
@Override public void writeTypePrefixForScalar(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { // can still wrap ok jgen.writeStartObject(); jgen.writeFieldName(_idResolver.idFromValue(value)); }
@Override public void writeTypePrefixForScalar(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { // can still wrap ok jgen.writeStartObject(); jgen.writeFieldName(_idResolver.idFromValueAndType(value, type)); }
@Override public void writeTypePrefixForScalar(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { // only need the wrapper array jgen.writeStartArray(); jgen.writeString(_idResolver.idFromValue(value)); }
@Override public void writeTypePrefixForArray(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { jgen.writeStartArray(); jgen.writeString(_idResolver.idFromValueAndType(value, type)); jgen.writeStartArray(); }
@Override public void writeTypePrefixForObject(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { jgen.writeStartArray(); jgen.writeString(_idResolver.idFromValue(value)); jgen.writeStartObject(); }
@Override public void writeTypePrefixForObject(Object value, JsonGenerator jgen, Class<?> type) throws IOException, JsonProcessingException { jgen.writeStartArray(); jgen.writeString(_idResolver.idFromValueAndType(value, type)); jgen.writeStartObject(); }
@Override public void writeTypePrefixForArray(Object value, JsonGenerator jgen) throws IOException, JsonProcessingException { jgen.writeStartArray(); jgen.writeString(_idResolver.idFromValue(value)); jgen.writeStartArray(); }