0

这是我的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);
    }
}
4

1 回答 1

0

听起来您可能需要为 DefaultConfigurationProperty 的值字段添加自定义序列化程序。您应该能够使用 Jackson 自定义序列化程序 [1] 来完成此操作。

[1] http://wiki.fasterxml.com/JacksonHowToCustomSerializers

于 2016-01-15T16:18:48.993 回答