2012-02-02 6 views
3

JACKSONフィールドのラッパーをどのように含めるべきですか?JACKSONフィールドのラッパーをどのように含めるべきですか?

public class AuthType { 
    Map<String,String> properties; 

    public Map<String, String> getProperties() { 
     return properties; 
    } 

    public void setProperties(Map<String, String> properties) { 
     this.properties = properties; 
    } 

} 

それは

{"properties":{"authType":"XYZ"}} 

返しますが、私は

{"authType":"XYZ"} 

どれでも注釈をしたいですか?

サポートがありません。http://jira.codehaus.org/browse/JACKSON-765回避策はありますか?

+0

を使用することができますなぜあなたは単に行わないobjectMappger.writeValueAsString(authType.getProperties())? – weekens

答えて

0

実際にクラスが単純な場合は、Jacksonのcustom serializersを使用するか、単にtreeとしてシリアル化してください。

0

マップに@JsonAnyGetterを追加できます。それを読み取る必要がある場合は、一致する@JsonAnySetterを定義します。

1

ジャクソン1.9以降では、あなたが@JsonUnwrapped注釈

public class AuthType { 
    Map<String,String> properties; 

    @JsonUnwrapped 
    public Map<String, String> getProperties() { 
     return properties; 
    } 

    public void setProperties(Map<String, String> properties) { 
     this.properties = properties; 
    } 
} 
関連する問題