以下是我的GET
方法的示例代码,该代码应返回xml
序列化版本的ConfigurationProperty
作为回复。
除非ConfigurationProperty
设置为value
,否则它会在大多数时间序列化ArrayList
模型。
当使用javax.ws.rs.Produces
完成序列化时,可能是什么原因以及如何解决?
@GET
@Path("{id}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ConfigurationProperty getConfigurationProperty(@PathParam("id") Id id)
{
ConfigurationProperty cp = service.get(ConfigurationProperty.class, id);
return checked(cp);
}
cp
的内容:
cp DefaultConfigurationProperty (id=293)
__scsIsPartialObject false
__scsTransientServiceFields HashMap<K,V> (id=312)
createdBy "migration" (id=313)
createdOn Date (id=314)
id Id (id=315)
key "catalog/cron/product_status_export/try_languages" (id=316)
merchantIds null
modifiedBy null
modifiedOn null
requestContextIds null
storeIds null
value ArrayList<E> (id=317)
elementData Object[10] (id=326)
[0] MongoValue (id=13837)
object "de" (id=13846)
[1] MongoValue (id=13838)
object "en" (id=13853)
[2] MongoValue (id=13839)
object "global" (id=13860)
modCount 3
size 3
version null
MongoValue.java
:
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.UUID;
import com.app.core.service.api.Value;
import com.app.core.type.TypeConverter;
public final class MongoValue implements Value
{
Object object = null;
public MongoValue(Object object)
{
this.object = object;
}
@Override
public String getString()
{
return TypeConverter.asString(object);
}
@Override
public Integer getInteger()
{
return TypeConverter.asInteger(object);
}
@Override
public Long getLong()
{
return TypeConverter.asLong(object);
}
@Override
public Double getDouble()
{
return TypeConverter.asDouble(object);
}
@Override
public Float getFloat()
{
return TypeConverter.asFloat(object);
}
@Override
public Short getShort()
{
return TypeConverter.asShort(object);
}
@Override
public Boolean getBoolean()
{
return TypeConverter.asBoolean(object);
}
@Override
public BigDecimal getBigDecimal()
{
return TypeConverter.asBigDecimal(object);
}
@Override
public BigInteger getBigInteger()
{
return TypeConverter.asBigInteger(object);
}
@Override
public Character getChar()
{
return TypeConverter.asCharacter(object);
}
@Override
public <E extends Enum<E>> E getEnum(Class<E> enumType)
{
return TypeConverter.asEnum(enumType, object);
}
@Override
public UUID getUUID()
{
return TypeConverter.asUUID(object);
}
@Override
public String getAscii()
{
return TypeConverter.asASCII(object);
}
@Override
public Date getDate()
{
return TypeConverter.asDate(object);
}
@Override
public Object getRaw()
{
return TypeConverter.asRaw(object);
}
@Override
public String toString()
{
return String.valueOf(object);
}
}
答案 0 :(得分:0)
听起来您可能需要为DefaultConfigurationProperty的值字段添加自定义序列化程序。您应该能够使用Jackson自定义序列化器[1]来完成此任务。