• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JAXBContextProperties类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.persistence.jaxb.JAXBContextProperties的典型用法代码示例。如果您正苦于以下问题:Java JAXBContextProperties类的具体用法?Java JAXBContextProperties怎么用?Java JAXBContextProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JAXBContextProperties类属于org.eclipse.persistence.jaxb包,在下文中一共展示了JAXBContextProperties类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: Mapper

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
/**
 * Private constructor that will create the JAXB context.
 */
public Mapper(String mediaType) {
	this.mediaType=mediaType;
	try {
		if(context==null){
			if(mediaType.equals(MimeMediaType.JSON)){
				ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 
				InputStream iStream = classLoader.getResourceAsStream("json-binding.xml"); 
				Map<String, Object> properties = new HashMap<String, Object>(); 
				properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream);
				context = JAXBContext.newInstance(resourcePackage, classLoader , properties);
			} else {
				context = JAXBContext.newInstance(resourcePackage);
			}
		}
	} catch (JAXBException e) { 
		LOGGER.error("Create JAXBContext error", e);
	}
}
 
开发者ID:HPCC-Cloud-Computing,项目名称:IoT,代码行数:22,代码来源:Mapper.java


示例2: JSONConvertor

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
public JSONConvertor(Class<T> type, Class<T>[] types) {
		this.t = type;

		Map<String, Object> properties = new HashMap<String, Object>(3);
		properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "net/herit/iot/onem2m/resource/oxm.xml");
		properties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
//		properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, isJsonIncludeRoot);

		try {
			if (types != null) {
				context = JAXBContext.newInstance(types, properties);	
			} else {
				context = JAXBContext.newInstance(new Class[] {t}, properties);
			}

			initialize();
			
		} catch (Exception e) {
			// TBD
		}
	}
 
开发者ID:iotoasis,项目名称:SI,代码行数:22,代码来源:JSONConvertor.java


示例3: DaoJSONConvertor

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
public DaoJSONConvertor(Class<T> type, Class<T>[] types) {
	this.t = type;

	Map<String, Object> properties = new HashMap<String, Object>(3);
	properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "net/herit/iot/onem2m/resource/oxm.xml");
	properties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
	properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);

	try {
		if (types != null) {
			context = JAXBContext.newInstance(types, properties);	
		} else {
			context = JAXBContext.newInstance(new Class[] {t}, properties);
		}

		initialize();
		
	} catch (Exception e) {
		// TBD
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:22,代码来源:DaoJSONConvertor.java


示例4: jaxbUnmarshall

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object jaxbUnmarshall(Object schemaObject, String json) throws JAXBException {
    Class cls = schemaObject.getClass();
    Class[] types = new Class[1];
    types[0] = cls;
    Map<String, String> namespacePrefixMapper = new HashMap<>(3);
    namespacePrefixMapper.put("router", "router");
    namespacePrefixMapper.put("provider", "provider");
    namespacePrefixMapper.put("binding", "binding");
    Map<String, Object> jaxbProperties = new HashMap<>(2);
    jaxbProperties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
    jaxbProperties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);
    jaxbProperties.put(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, ':');
    jaxbProperties.put(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper);
    JAXBContext jc = JAXBContext.newInstance(types, jaxbProperties);

    Unmarshaller unmarshaller = jc.createUnmarshaller();
    unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper);

    StringReader reader = new StringReader(json);
    StreamSource stream = new StreamSource(reader);
    return unmarshaller.unmarshal(stream, cls).getValue();
}
 
开发者ID:opendaylight,项目名称:neutron,代码行数:24,代码来源:JaxbTestHelper.java


示例5: toJson

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
/**
 * Converts a {@link VulnerabilityType} entry to JSON.
 * 
 * @param entry
 * @param name
 * @param nvdNam
 * @return the JSON representation as string
 * @throws JAXBException
 */
private String toJson(VulnerabilityType entry, String name, String nvdName)
		throws JAXBException {

	Map<String, Object> properties = new HashMap<String, Object>(2);
	properties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
	properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);

	// convert a single CVE entry to JSON
	JAXBContext jc = JAXBContext.newInstance(
			new Class[] { VulnerabilityType.class }, properties);
	Marshaller marshaller = jc.createMarshaller();
	// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
	StringWriter swriter = new StringWriter();
	marshaller.marshal(entry, swriter);
	return swriter.toString();
}
 
开发者ID:frosenberg,项目名称:elasticsearch-nvd-river,代码行数:26,代码来源:NvdRiver.java


示例6: createJAXBContext

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
private static JAXBContext createJAXBContext() {
    Map<String, Object> jaxbProperties = new HashMap<String, Object>();
    jaxbProperties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
    jaxbProperties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);
    JAXBContext jc;
    try {
        jc = JAXBContext.newInstance(
                new Class[] { BenchmarkBean.class, SystemBean.class, ConfigurationParamBean.class, BenchmarkListBean.class,
                    ChallengesListBean.class, ChallengeBean.class, ChallengeTaskBean.class,
                    ExperimentBean.class, ExperimentsListBean.class}, jaxbProperties);
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
    return jc;
}
 
开发者ID:hobbit-project,项目名称:platform,代码行数:16,代码来源:MarshallerUtil.java


示例7: getMarshaller

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
private Marshaller getMarshaller() throws JAXBException {
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json");
    marshaller.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, false);

    return marshaller;
}
 
开发者ID:arquillian,项目名称:arquillian-recorder,代码行数:9,代码来源:JSONExporter.java


示例8: MoxyJsonConfigResolver

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
public MoxyJsonConfigResolver() {
	MoxyJsonConfig jsonConfig = new MoxyJsonConfig();
	jsonConfig.property(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
	this.config = jsonConfig;
}
 
开发者ID:color-coding,项目名称:ibas-framework,代码行数:6,代码来源:MoxyJsonConfigResolver.java


示例9: JsonConfig

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
public JsonConfig() {
	MoxyJsonConfig jsonConfig = new MoxyJsonConfig();
	jsonConfig.property(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
	this.config = jsonConfig;
}
 
开发者ID:color-coding,项目名称:ibas-framework,代码行数:6,代码来源:JsonConfig.java


示例10: JAXBSerializer

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
public JAXBSerializer() throws JAXBException {
    this.reflections = new Reflections(
            new ConfigurationBuilder()
            .forPackages("c1c/v8fs/jaxb/bindings")
            .setScanners(new ResourcesScanner()));

    List<Object> bindings = reflections.getResources(
            (nm) -> (nm != null ? nm.matches(".+-bindings\\.xml") : false)
    ).stream()
            .map((nm) -> Resources.getResource(nm))
            .collect(Collectors.toList());

    Map<String, Object> bindingMap = new HashMap<>();
    bindingMap.put("c1c.v8fs", bindings);

    Map<String, Object> properties = new HashMap<>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindingMap);

    this.jaxbContext = JAXBContextFactory.createContext(
            new Class[]{
                Container.class,
                ContainerHeader.class,
                Chain.class,
                Chunk.class,
                ChunkHeader.class,
                Attributes.class,
                c1c.v8fs.File.class,
                Index.class,
                IndexEntry.class
            }, properties
    );

    List<Object> bindingsSep = reflections.getResources(
            (nm) -> (nm != null ? nm.matches(".+-bindings-sep\\.xml") : false)
    ).stream()
            .map((nm) -> Resources.getResource(nm))
            .collect(Collectors.toList());

    Map<String, Object> bindingMapSep = new HashMap<>();
    bindingMapSep.put("c1c.v8fs", bindingsSep);

    Map<String, Object> propertiesSep = new HashMap<>();
    propertiesSep.put(JAXBContextProperties.OXM_METADATA_SOURCE, bindingMapSep);

    this.jaxbChunkDataContext = JAXBContextFactory.createContext(
            new Class[]{
                Chunk.class
            }, propertiesSep
    );

    this.jaxbMarshaller = this.jaxbContext.createMarshaller();
    this.jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    this.jaxbChunkDataMarshaller = this.jaxbChunkDataContext.createMarshaller();
    this.jaxbChunkDataMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    this.jaxbUnmarshaller = this.jaxbContext.createUnmarshaller();
    this.jaxbChunkDataUnmarshaller = this.jaxbChunkDataContext.createUnmarshaller();

}
 
开发者ID:psyriccio,项目名称:v8fs,代码行数:59,代码来源:JAXBSerializer.java


示例11: testXml2Json

import org.eclipse.persistence.jaxb.JAXBContextProperties; //导入依赖的package包/类
@Test
public void testXml2Json() throws JAXBException, IOException {
	// read XML into a JAXB object structure
	URL resource = getClass().getResource("/nvdcve-2.0-2003.xml");
  System.out.println("Parsing " + resource);	
	JAXBContext jaxbContext = JAXBContext.newInstance(Nvd.class);
	Unmarshaller um = jaxbContext.createUnmarshaller();
	Nvd nvd = (Nvd)um.unmarshal(resource.openStream());
   
   // JAXB to JSON properties
   Map<String, Object> properties = new HashMap<String, Object>(2);
   properties.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
   properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false);
	
   // convert a single CVE entry to JSON
   JAXBContext jc = JAXBContext.newInstance(new Class[] { VulnerabilityType.class }, properties);
   Marshaller marshaller = jc.createMarshaller();
   marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
   StringWriter swriter = new StringWriter();
   for (VulnerabilityType entry : nvd.getEntry()) {
   	marshaller.marshal(entry, swriter);
     assertTrue(swriter.toString().startsWith("{"));
   }
   
   jc = JAXBContext.newInstance(new Class[] { Nvd.class }, properties);
   marshaller = jc.createMarshaller();
   marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
   swriter = new StringWriter();
   marshaller.marshal(nvd, swriter);
   
   JsonParser p = new JsonFactory().createParser(swriter.toString());
   JsonToken token = null;
   int level = 0, cveEntries = 0;

   while ((token = p.nextValue()) != null) {
   	if (token.isStructStart()) {
   		level++;
   	} else if (token.isStructEnd()) {
   		level--;
   	}   
   	if (level == 2) cveEntries++; // we want to count all CVEs in the array that is at level 2
   }
   p.close();
   System.out.printf("cveEntries = %s", cveEntries);
   assertEquals(1515, cveEntries-1);    
 }
 
开发者ID:frosenberg,项目名称:elasticsearch-nvd-river,代码行数:47,代码来源:NvdXmlTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ApplicationMasterProtocolPB类代码示例发布时间:2022-05-22
下一篇:
Java ReflectHelper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap