Jersey 2.0相当于POJOMappingFeature [英] Jersey 2.0 equivalent to POJOMappingFeature

查看:175
本文介绍了Jersey 2.0相当于POJOMappingFeature的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用泽西岛的经验< 2.0。现在我正在尝试构建一个war应用程序以提供JSON Webservice API。

I have some experience using Jersey < 2.0. Now I am trying to build a war application to provide a JSON Webservice API.

我现在正在努力配置Moxy并且它接缝是相当长的时间比添加更复杂的方式

I am now struggling for a considerable amount of time trying to configure Moxy and it seams to be way more complicated than what was adding

    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>

返回泽西岛的web.xml< 2.0。

to your web.xml back in Jersey < 2.0.

是否有可能只说请添加json支持?

Is there some possibility to just say "please add json support"?

目前我得到了很多服务器上没有任何日志条目的内部服务器错误错误,只是想我必须做一些完全错误的事情,这可能不会那么难

Currently I just get a lot of Internal Server Error errors without any log entries on the server and just think "I have to do something totally wrong, this can't be so hard"

任何人都可以给予我暗示一下?

Can anyone give me a hint?

推荐答案

您可以配置通过JAX-RS 应用程序<配置 MOXyJsonProvider 类,将 EclipseLink MOXy 作为JSON绑定提供程序 class。

You can configure EclipseLink MOXy as the JSON-binding provider by configuring the MOXyJsonProvider class through a JAX-RS Application class.

示例#1

package org.example;

import java.util.*;
import javax.ws.rs.core.Application;
import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;

public class CustomerApplication  extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        HashSet<Class<?>> set = new HashSet<Class<?>>(2);
        set.add(MOXyJsonProvider.class);
        set.add(CustomerService.class);
        return set;
    }

}

示例#2

package org.example;

import java.util.*;
import javax.ws.rs.core.Application;
import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;

public class CustomerApplication  extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        HashSet<Class<?>> set = new HashSet<Class<?>>(1);
        set.add(ExampleService.class);
        return set;
    }

    @Override
    public Set<Object> getSingletons() {
        MOXyJsonProvider moxyJsonProvider = new MOXyJsonProvider();

        moxyJsonProvider.setAttributePrefix("@");
        moxyJsonProvider.setFormattedOutput(true);
        moxyJsonProvider.setIncludeRoot(true);
        moxyJsonProvider.setMarshalEmptyCollections(false);
        moxyJsonProvider.setValueWrapper("$");

        Map<String, String> namespacePrefixMapper = new HashMap<String, String>(1);
        namespacePrefixMapper.put("http://www.example.org/customer", "cust");
        moxyJsonProvider.setNamespacePrefixMapper(namespacePrefixMapper);
        moxyJsonProvider.setNamespaceSeparator(':');

        HashSet<Object> set = new HashSet<Object>(1);
        set.add(moxyJsonProvider);
        return set;
    }

} 

更多信息

  • http://blog.bdoughan.com/2012/05/moxy-as-your-jax-rs-json-provider.html
  • http://blog.bdoughan.com/2013/06/moxy-is-new-default-json-binding.html

这篇关于Jersey 2.0相当于POJOMappingFeature的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆