English 中文(简体)
沼泽地 地图<String,String>
原标题:Marshal a java.util.Map<String,String>

我要问的下一个问题,是我的亲善大使。

import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author Martin Burchard
 * 
 */
@XmlRootElement(name = "user")
@XmlAccessorType(XmlAccessType.FIELD)
public class User {
    private String id;
    private String nickname;
    private String email;
    private String password;
    private Map<String, String> user_attributes;

}

Currently the service delivers the following JSON (indented for better reading):

{
    "user" : {
        "id" : "9bdf40ea-6d25-4bc3-94ad-4a3d38d2c3ca",
        "email" : "[email protected]",
        "password" : "xXpd9Pl-1pFBFuX9E0hAYGSDTyJQPYkOtXGvRCrEtMM",
        "user_attributes" : {
            "entry" : [{
                    "key" : "num",
                    "value" : 123
                }, {
                    "key" : "type",
                    "value" : "nix"
                }
            ]
        }
    }
}

The funny think is, internally the num 123 is a java.lang.String...

我不理解这里解释的内容:http://cxf.apache.org/docs/jax-rs-data- bindings.html#JAX-RSDataBleds-Dealing withJSONarrayserializationissues”rel=“nofollow” http://cxf.apache.org/docs/jax-rs-data- bindings.html#JRP-RSDataBelles-Dealing withJarraSONyserializationissues

我谨请各位:

{
    "user" : {
        "id" : "9bdf40ea-6d25-4bc3-94ad-4a3d38d2c3ca",
        "email" : "[email protected]",
        "password" : "xXpd9Pl-1pFBFuX9E0hAYGSDTyJQPYkOtXGvRCrEtMM",
        "user_attributes" : {
            "num" : "123",
            "type" : "nix"
        }
    }
}

I changed the JSON provider to Jackson. Now my JSON looks like I like it...

问题回答

我所想的唯一事情是利用日本宇宙航空研究开发机构XmlAdapter。 您可以确定某个物体(在您的个案地图中)如何被绘制成名星。

使用适当的JSON图书馆,如Jackson





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签