本文整理汇总了Java中org.eclipse.persistence.jaxb.MarshallerProperties类的典型用法代码示例。如果您正苦于以下问题:Java MarshallerProperties类的具体用法?Java MarshallerProperties怎么用?Java MarshallerProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MarshallerProperties类属于org.eclipse.persistence.jaxb包,在下文中一共展示了MarshallerProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMarschallingMessage
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
@Test
public void testMarschallingMessage() throws Exception {
JAXBContext jc = JAXBContext.newInstance(Message.class);
// Create the Marshaller Object using the JaxB Context
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT,false);
Message message = new Message();
message.setMessage("success");
// Marshal the employee object to JSON and print the output to console
marshaller.marshal(message, System.out);
}
示例2: testMarschallAcessToken
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
@Test @Ignore
public void testMarschallAcessToken() throws Exception {
JAXBContext jc = JAXBContext.newInstance(AccessToken.class);
// Create the Marshaller Object using the JaxB Context
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT,false);
AccessToken accessToken = new AccessToken();
accessToken.setAccessToken("eyJhbGciOiJSU");
accessToken.setExpiresIn(600);
accessToken.setExpiresIn(60);
accessToken.setRefreshToken("_dqAGxefbg0u58JAkz4nBkNE");
accessToken.setTokenType("token_type");
// Marshal the employee object to JSON and print the output to console
marshaller.marshal(accessToken, System.out);
}
示例3: configure
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
@Override
protected Application configure() {
//enable(TestProperties.LOG_TRAFFIC);
//enable(TestProperties.DUMP_ENTITY);
//
// TODO: load web.xml directly
// .property(
// "contextConfigLocation",
// "classpath:**/my-web-test-context.xml"
//
return new ResourceConfig(MyResource.class)
.register(ParsecMoxyProvider.class)
.register(JaxbExceptionMapper.class)
.property(JaxbExceptionMapper.PROP_JAXB_DEFAULT_ERROR_CODE, JAXB_ERROR_CODE)
.property(JaxbExceptionMapper.PROP_JAXB_DEFAULT_ERROR_MSG, JAXB_ERROR_MSG)
.register(ValidationConfigurationContextResolver.class)
.register(ParsecValidationExceptionMapper.class)
.property(ParsecValidationExceptionMapper.PROP_VALIDATION_DEFAULT_ERROR_CODE, VALIDATION_ERROR_CODE)
.property(ParsecValidationExceptionMapper.PROP_VALIDATION_DEFAULT_ERROR_MSG, VALIDATION_ERROR_MSG)
.property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
.register(new MoxyJsonConfig().setFormattedOutput(true)
.property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE).resolver());
}
示例4: transformJsonUpload
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
private String transformJsonUpload(final Suggestion suggestion, final Path transformation) throws IOException, TransformationException {
try(final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
try {
final JAXBContext context = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[]{Suggestion.class}, null);
final Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, org.eclipse.persistence.oxm.MediaType.APPLICATION_JSON);
marshaller.setProperty(MarshallerProperties.JSON_ATTRIBUTE_PREFIX, null);
marshaller.setProperty(MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, false);
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper);
marshaller.setProperty(MarshallerProperties.JSON_NAMESPACE_SEPARATOR, ':');
marshaller.marshal(suggestion, os);
try(final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
os.reset();
jsonTransformer.transform(is, transformation, os);
return new String(os.toByteArray(), StandardCharsets.UTF_8);
}
} catch (final JAXBException e) {
throw new TransformationException(e);
}
}
}
示例5: objToString
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
/**
* Converts a resource Java object into resource XML representation.
*
* @param object
* - resource Java object
* @return resource XML representation
*/
@Override
public String objToString(Object obj) {
try {
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
OutputStream outputStream = new ByteArrayOutputStream();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE,mediaType);
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
marshaller.marshal(obj, outputStream);
return outputStream.toString();
} catch (JAXBException e) {
LOGGER.error("JAXB marshalling error!", e);
}
return null;
}
示例6: initialize
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
private void initialize(String schema) throws JAXBException {
um = context.createUnmarshaller();
um.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/xml");
m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
new NamespacePrefixMapper() {
@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
if(namespaceUri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE)) {
return "xsi";
} else
return "m2m";
}
});
String schemaLocation = schema;
if(schemaLocation != null) {
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.onem2m.org/xml/protocols " + schemaLocation);
}
m.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml");
}
示例7: objectToXml
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
/**
* Returns XML representation of the object using the herd custom character escape handler.
*
* @param obj the Java object to be serialized
* @param formatted specifies whether or not the marshalled XML data is formatted with line feeds and indentation
*
* @return the XML representation of this object
* @throws JAXBException if a JAXB error occurred.
*/
public String objectToXml(Object obj, boolean formatted) throws JAXBException
{
JAXBContext requestContext = JAXBContext.newInstance(obj.getClass());
Marshaller requestMarshaller = requestContext.createMarshaller();
if (formatted)
{
requestMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
requestMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
}
// Specify a custom character escape handler to escape XML 1.1 restricted characters.
requestMarshaller.setProperty(MarshallerProperties.CHARACTER_ESCAPE_HANDLER, herdCharacterEscapeHandler);
StringWriter sw = new StringWriter();
requestMarshaller.marshal(obj, sw);
return sw.toString();
}
示例8: init
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
private static void init() {
// Initialise JAXB
try {
JAXBContext jc = JAXBContext.newInstance(new Class[] { ConceptInclusion.class, RoleInclusion.class,
NamedConcept.class, Conjunction.class, Existential.class, Datatype.class, NamedFeature.class,
NamedRole.class, IntegerLiteral.class, StringLiteral.class, LongLiteral.class, DateLiteral.class,
DecimalLiteral.class, BigIntegerLiteral.class, FloatLiteral.class, DoubleLiteral.class,
BooleanLiteral.class});
marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller = jc.createUnmarshaller();
unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
} catch(JAXBException e) {
log.error("There was a problem initialising JAXB.", e);
}
}
示例9: createJsonMarshaller
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
private Marshaller createJsonMarshaller() {
try {
Marshaller marshaller;
marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, StringUtil.ENCODING_UTF8);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
return marshaller;
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
示例10: configureClient
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
@Override
protected void configureClient(final ClientConfig config) {
super.configureClient(config);
config.register(MoxyJsonFeature.class)
.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true)
.register(new MoxyJsonConfig().setFormattedOutput(true)
// Turn off BV otherwise the entities on server would be validated by MOXy as well.
.property(MarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE).resolver());
}
示例11: createJsonMarshaller
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
private Marshaller createJsonMarshaller() throws JAXBException {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, StringUtil.ENCODING_UTF8);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
return marshaller;
}
示例12: getString
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
public static <T> String getString(T object) {
try {
JAXBContext c = JAXBContextFactory.createContext(new Class[]{object.getClass()}, null);
Marshaller m = c.createMarshaller();
m.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
StringWriter sw = new StringWriter();
m.marshal(object, sw);
return sw.toString();
}
catch (JAXBException e) {
throw new UserInputException("Get JSON String from Object Failed.", e);
}
}
示例13: unmarshall2Json
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
private String unmarshall2Json(Jobconfig jobconfig) throws PropertyException, JAXBException {
StringWriter sw = new StringWriter();
JAXBContext jc = JAXBContext.newInstance(Jobconfig.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.marshal(jobconfig, sw);
return sw.toString();
}
示例14: saveJSON
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
public static <T> void saveJSON(OutputStream out, T entity, boolean includeRoot, boolean formated)
throws JAXBException, IOException {
final JAXBContext jc = JAXBContext.newInstance(populateEntities(entity.getClass()));
final Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, includeRoot);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formated);
marshaller.marshal(entity, out);
}
示例15: toJSON
import org.eclipse.persistence.jaxb.MarshallerProperties; //导入依赖的package包/类
public static <T> String toJSON(T entity, boolean includeRoot) throws JAXBException, IOException {
final JAXBContext jc = JAXBContext.newInstance(populateEntities(entity.getClass()));
final Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, includeRoot);
final StringWriter sw = new StringWriter();
marshaller.marshal(entity, sw);
return sw.toString();
}