@Test public void renderWithCustomSerializerLocatedByFactory() throws Exception { SerializerFactory factory = new DelegatingSerializerFactory(null); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializerFactory(factory); view.setObjectMapper(mapper); Object bean = new TestBeanSimple(); Map<String, Object> model = new HashMap<String, Object>(); model.put("foo", bean); model.put("bar", new TestChildBean()); view.render(model, request, response); String result = response.getContentAsString(); assertTrue(result.length() > 0); assertTrue(result.contains("\"foo\":{\"testBeanSimple\":\"custom\"}")); validateResult(); }
public SerializerFactory withConfig(SerializerFactory.Config paramConfig) { if (this._factoryConfig == paramConfig) return this; if (getClass() != BeanSerializerFactory.class) throw new IllegalStateException("Subtype of BeanSerializerFactory (" + getClass().getName() + ") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " + "additional serializer definitions"); return new BeanSerializerFactory(paramConfig); }
public SerializerFactory.Config withAdditionalKeySerializers(Serializers paramSerializers) { if (paramSerializers == null) throw new IllegalArgumentException("Can not pass null Serializers"); Serializers[] arrayOfSerializers = (Serializers[])ArrayBuilders.insertInListNoDup(this._additionalKeySerializers, paramSerializers); return new ConfigImpl(this._additionalSerializers, arrayOfSerializers, this._modifiers); }
public SerializerFactory.Config withSerializerModifier(BeanSerializerModifier paramBeanSerializerModifier) { if (paramBeanSerializerModifier == null) throw new IllegalArgumentException("Can not pass null modifier"); BeanSerializerModifier[] arrayOfBeanSerializerModifier = (BeanSerializerModifier[])ArrayBuilders.insertInListNoDup(this._modifiers, paramBeanSerializerModifier); return new ConfigImpl(this._additionalSerializers, this._additionalKeySerializers, arrayOfBeanSerializerModifier); }
protected StdSerializerProvider(SerializationConfig paramSerializationConfig, StdSerializerProvider paramStdSerializerProvider, SerializerFactory paramSerializerFactory) { super(paramSerializationConfig); if (paramSerializationConfig == null) throw new NullPointerException(); this._serializerFactory = paramSerializerFactory; this._serializerCache = paramStdSerializerProvider._serializerCache; this._unknownTypeSerializer = paramStdSerializerProvider._unknownTypeSerializer; this._keySerializer = paramStdSerializerProvider._keySerializer; this._nullValueSerializer = paramStdSerializerProvider._nullValueSerializer; this._nullKeySerializer = paramStdSerializerProvider._nullKeySerializer; this._rootNames = paramStdSerializerProvider._rootNames; this._knownSerializers = this._serializerCache.getReadOnlyLookupMap(); }
public JsonSchema generateJsonSchema(Class<?> paramClass, SerializationConfig paramSerializationConfig, SerializerFactory paramSerializerFactory) throws JsonMappingException { if (paramClass == null) throw new IllegalArgumentException("A class must be provided"); StdSerializerProvider localStdSerializerProvider = createInstance(paramSerializationConfig, paramSerializerFactory); if (localStdSerializerProvider.getClass() != getClass()) throw new IllegalStateException("Broken serializer provider: createInstance returned instance of type " + localStdSerializerProvider.getClass() + "; blueprint of type " + getClass()); JsonSerializer localJsonSerializer = localStdSerializerProvider.findValueSerializer(paramClass, null); if ((localJsonSerializer instanceof SchemaAware)); for (JsonNode localJsonNode = ((SchemaAware)localJsonSerializer).getSchema(localStdSerializerProvider, null); !(localJsonNode instanceof ObjectNode); localJsonNode = JsonSchema.getDefaultSchemaNode()) throw new IllegalArgumentException("Class " + paramClass.getName() + " would not be serialized as a JSON object and therefore has no schema"); return new JsonSchema((ObjectNode)localJsonNode); }
public final void serializeValue(SerializationConfig paramSerializationConfig, JsonGenerator paramJsonGenerator, Object paramObject, SerializerFactory paramSerializerFactory) throws IOException, JsonGenerationException { if (paramSerializerFactory == null) throw new IllegalArgumentException("Can not pass null serializerFactory"); StdSerializerProvider localStdSerializerProvider = createInstance(paramSerializationConfig, paramSerializerFactory); if (localStdSerializerProvider.getClass() != getClass()) throw new IllegalStateException("Broken serializer provider: createInstance returned instance of type " + localStdSerializerProvider.getClass() + "; blueprint of type " + getClass()); localStdSerializerProvider._serializeValue(paramJsonGenerator, paramObject); }
public final void serializeValue(SerializationConfig paramSerializationConfig, JsonGenerator paramJsonGenerator, Object paramObject, JavaType paramJavaType, SerializerFactory paramSerializerFactory) throws IOException, JsonGenerationException { if (paramSerializerFactory == null) throw new IllegalArgumentException("Can not pass null serializerFactory"); StdSerializerProvider localStdSerializerProvider = createInstance(paramSerializationConfig, paramSerializerFactory); if (localStdSerializerProvider.getClass() != getClass()) throw new IllegalStateException("Broken serializer provider: createInstance returned instance of type " + localStdSerializerProvider.getClass() + "; blueprint of type " + getClass()); localStdSerializerProvider._serializeValue(paramJsonGenerator, paramObject, paramJavaType); }
public SerializerFactory withConfig(SerializerFactory.Config paramConfig) { if (this._factoryConfig == paramConfig) return this; if (getClass() != BeanSerializerFactory.class) throw new IllegalStateException("Subtype of BeanSerializerFactory (" + getClass().getName() + ") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with additional serializer definitions"); return new BeanSerializerFactory(paramConfig); }
public final void serializeValue(SerializationConfig paramSerializationConfig, JsonGenerator paramJsonGenerator, Object paramObject, SerializerFactory paramSerializerFactory) { if (paramSerializerFactory == null) throw new IllegalArgumentException("Can not pass null serializerFactory"); StdSerializerProvider localStdSerializerProvider = createInstance(paramSerializationConfig, paramSerializerFactory); if (localStdSerializerProvider.getClass() != getClass()) throw new IllegalStateException("Broken serializer provider: createInstance returned instance of type " + localStdSerializerProvider.getClass() + "; blueprint of type " + getClass()); localStdSerializerProvider._serializeValue(paramJsonGenerator, paramObject); }
public StdEscapeHTMLSerializerProvider(SerializationConfig config, StdEscapeHTMLSerializerProvider src, SerializerFactory jsf) { super(config, src, jsf); }
public CustomSerializerFactory(SerializerFactory.Config paramConfig) { super(paramConfig); }
public SerializerFactory withConfig(SerializerFactory.Config paramConfig) { if (getClass() != CustomSerializerFactory.class) throw new IllegalStateException("Subtype of CustomSerializerFactory (" + getClass().getName() + ") has not properly overridden method 'withAdditionalSerializers': can not instantiate subtype with " + "additional serializer definitions"); return new CustomSerializerFactory(paramConfig); }
protected BeanSerializerFactory(SerializerFactory.Config paramConfig) { if (paramConfig == null) paramConfig = new ConfigImpl(); this._factoryConfig = paramConfig; }
public SerializerFactory.Config getConfig() { return this._factoryConfig; }
public SerializerFactory.Config withAdditionalSerializers(Serializers paramSerializers) { if (paramSerializers == null) throw new IllegalArgumentException("Can not pass null Serializers"); return new ConfigImpl((Serializers[])ArrayBuilders.insertInListNoDup(this._additionalSerializers, paramSerializers), this._additionalKeySerializers, this._modifiers); }
protected StdSerializerProvider createInstance(SerializationConfig paramSerializationConfig, SerializerFactory paramSerializerFactory) { return new StdSerializerProvider(paramSerializationConfig, this, paramSerializerFactory); }
public boolean hasSerializerFor(SerializationConfig paramSerializationConfig, Class<?> paramClass, SerializerFactory paramSerializerFactory) { return createInstance(paramSerializationConfig, paramSerializerFactory)._findExplicitUntypedSerializer(paramClass, null) != null; }
protected BeanSerializerFactory(SerializerFactory.Config paramConfig) { if (paramConfig == null) paramConfig = new BeanSerializerFactory.ConfigImpl(); this._factoryConfig = paramConfig; }
/** * 重写createInstance函数 * * @param config * @param jsf * @return */ @Override protected StdSerializerProvider createInstance(SerializationConfig config, SerializerFactory jsf) { return new StdEscapeHTMLSerializerProvider(config, this, jsf); }