Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/MOXy/MOXy JSON Provider"

(New page: = MOXy JSON Provider = MOXy now includes an implementation (MOXyJsonProvider) that can be used directly or extended to make the integration even easier. == Using MOXyJsonProvider == ===...)
 
Line 1: Line 1:
= MOXy JSON Provider =
+
<div style="margin:5px;float:right;border:1px solid #000000;padding:5px">__TOC__</div>
  
MOXy now includes an implementation (MOXyJsonProvider) that can be used directly or extended to make the integration even easier.
+
=MOXy JSON Provider=
  
== Using MOXyJsonProvider ==
+
MOXy now includes an implementation ('''MOXyJsonProvider''') that can be used directly or extended to make the integration even easier.
  
=== Default Behaviour ===
+
==Using MOXyJsonProvider==
 +
 
 +
===Default Behaviour===
  
 
You can use a JAX-RS Application class to specify that '''MOXyJsonProvider''' should be used with your JAX-RS application.
 
You can use a JAX-RS Application class to specify that '''MOXyJsonProvider''' should be used with your JAX-RS application.
Line 28: Line 30:
 
   
 
   
 
}
 
}
 +
</source>
 +
</div>
 +
 +
==Configuration Options==
 +
 
 +
You can also use a JAX-RS Application class to specify an instance of MOXyJsonProvider to be used with your JAX-RS application.  This approach allows you customize the different configuration options offered by the MOXyJsonProvider.
 +
 +
<div style="width:850px">
 +
<source lang="java">
 +
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;
 +
    }
 +
 +
}
 
</source>
 
</source>
 
</div>
 
</div>

Revision as of 16:15, 15 June 2012

MOXy JSON Provider

MOXy now includes an implementation (MOXyJsonProvider) that can be used directly or extended to make the integration even easier.

Using MOXyJsonProvider

Default Behaviour

You can use a JAX-RS Application class to specify that MOXyJsonProvider should be used with your JAX-RS application.

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;
    }
 
}

Configuration Options

You can also use a JAX-RS Application class to specify an instance of MOXyJsonProvider to be used with your JAX-RS application. This approach allows you customize the different configuration options offered by the MOXyJsonProvider.

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;
    }
 
}

Back to the top