当前位置: 首页>>代码示例>>Java>>正文


Java MarshallerProperties类代码示例

本文整理汇总了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);
    
}
 
开发者ID:nmajorov,项目名称:keycloak_training,代码行数:17,代码来源:BindTest.java

示例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);
    
}
 
开发者ID:nmajorov,项目名称:keycloak_training,代码行数:22,代码来源:BindTest.java

示例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());

}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:25,代码来源:JerseyValidationTest.java

示例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);
        }
    }
}
 
开发者ID:BCDH,项目名称:TEI-Authorizer,代码行数:24,代码来源:JerseyClient.java

示例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;
}
 
开发者ID:HPCC-Cloud-Computing,项目名称:IoT,代码行数:23,代码来源:Mapper.java

示例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");
	}
 
开发者ID:iotoasis,项目名称:SI,代码行数:26,代码来源:XMLConvertor.java

示例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();
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:29,代码来源:XmlHelper.java

示例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);
    }
}
 
开发者ID:aehrc,项目名称:ontology-core,代码行数:18,代码来源:AxiomUtils.java

示例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);
    }
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:14,代码来源:JAXBWriter.java

示例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());
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:10,代码来源:JerseyValidationTest.java

示例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;
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:9,代码来源:JAXBWriter.java

示例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);
    }
}
 
开发者ID:douglasryanadams,项目名称:xunil,代码行数:16,代码来源:JSON.java

示例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();
    }
 
开发者ID:BiBiServ,项目名称:jobproxy,代码行数:14,代码来源:Chronos.java

示例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);
}
 
开发者ID:MyCoRe-Org,项目名称:MyVidCoRe,代码行数:11,代码来源:JsonUtils.java

示例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();
}
 
开发者ID:MyCoRe-Org,项目名称:MyVidCoRe,代码行数:11,代码来源:JsonUtils.java


注:本文中的org.eclipse.persistence.jaxb.MarshallerProperties类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。