English 中文(简体)
RESTEasy / Jettison, 回去 Java物体为JSON,没有根基
原标题:RESTEasy / Jettison, return Java object as JSON without the root node

I m 利用RESTEasy将 Java物体作为JSON物体(正在使用Jettison Mapped Convention for JSON marshelling)。

但是,我不想让它回头来。

例如

@XmlRootElement
public class Car{
    private Integer id;
    private String name;
}

这一类目标将产生下列结果:

{"Car":{"id":6,"name":"someName"}}

因为它实际上源自于

<Car>
    <id>6</id>
    <name>someName</name>
</Car>

但是,我不想 root。 我只想:

{"id":6,"name":"someName"}

因此,我可以与“后台”等客户图书馆一起使用。 j)

是否有办法(一些说明)迫使JSONmarshelling。

Sam,

最佳回答

I was faced with the exact same problem. After doing some research I found people suggested using resteasy-jackson-provider instead of jettison. It was claimed that jettison has a few issues and that what you re experiencing is one of them. I switched to Jackson and found that it solved this issue and probably a few others that I wasn t aware of. If you re using maven:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson-provider</artifactId>
    <version>2.1.0.GA</version>
</dependency>

If you do this, you may see some collisions between jettison. To avoid those make sure you don t have the jettison jars on your classpath.

问题回答

你们可以界定你们。 类似于:

var Car = Backbone.Model.extend({
    defaults: function() {
        return {Car: {id: 0, name:  bar }};
    }
}




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签