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

Java ToXmlGenerator类代码示例

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

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



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

示例1: exportStream

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
@Override
public void exportStream(OutputStream outputStream, Iterator<T> iterator) throws IOException, ClassNotFoundException, IllegalAccessException {
    JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);
    XmlFactory factory = new XmlFactory();
    ToXmlGenerator generator = factory.createGenerator(outputStream);

    generator.setCodec(xmlMapper);
    generator.writeRaw("<xml>");

    while (iterator.hasNext()) {

        generator.writeRaw(xmlMapper.writeValueAsString(iterator.next()));
    }
    generator.writeRaw("</xml>");

    generator.flush();
}
 
开发者ID:robeio,项目名称:robe,代码行数:20,代码来源:XMLExporter.java


示例2: writeStart

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
@Override
protected void writeStart(JsonGenerator jsonGenerator) throws IOException {
  ToXmlGenerator xmlGenerator = (ToXmlGenerator) jsonGenerator;
  xmlGenerator.setPrettyPrinter(new DefaultXmlPrettyPrinter());
  xmlGenerator.setNextName(new QName(null, XML_ROOT));
  xmlGenerator.writeStartObject();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:8,代码来源:TupleQueryResultXmlSerializer.java


示例3: serialize_GivesXmlResult_WhenQueryGivesData

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
@Test
public void serialize_GivesXmlResult_WhenQueryGivesData() throws IOException {
  // Arrange
  BindingSet bindingSet = new ListBindingSet(
      ImmutableList.of("identifier", "name", "yearOfFoundation", "craftMember", "fte"),
      DBEERPEDIA.BROUWTOREN, DBEERPEDIA.BROUWTOREN_NAME, DBEERPEDIA.BROUWTOREN_YEAR_OF_FOUNDATION,
      DBEERPEDIA.BROUWTOREN_CRAFT_MEMBER, DBEERPEDIA.BROUWTOREN_FTE);
  when(tupleQueryResult.hasNext()).thenReturn(true, false);
  when(tupleQueryResult.next()).thenReturn(bindingSet);

  XmlFactory factory = new XmlFactory();
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  ToXmlGenerator generator = factory.createGenerator(outputStream);

  // Act
  serializer.serialize(tupleQueryResult, generator, null);


  // Assert
  generator.close();
  assertThat(outputStream.toString(), containsString("<results>"));
  assertThat(outputStream.toString(), containsString(
      String.format("<identifier>%s</identifier>", DBEERPEDIA.BROUWTOREN.toString())));
  assertThat(outputStream.toString(), containsString("<name>Brouwtoren</name>"));
  assertThat(outputStream.toString(), containsString("<fte>1.8</fte>"));
  assertThat(outputStream.toString(), containsString("<craftMember>true</craftMember>"));
  assertThat(outputStream.toString(),
      containsString("<yearOfFoundation>2014</yearOfFoundation>"));
  assertThat(outputStream.toString(), containsString("</results>"));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:31,代码来源:TupleQueryResultXmlSerializerTest.java


示例4: addStaxNamespacePrefix

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
private void addStaxNamespacePrefix(Entry<String, String> entry, ToXmlGenerator toXmlGenerator) {
  try {
    toXmlGenerator.getStaxWriter().setPrefix(entry.getKey(), entry.getValue());
  } catch (XMLStreamException e) {
    e.printStackTrace();
  }
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:8,代码来源:ExtendedXmlMapper.java


示例5: serialize

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
@Override
public void serialize( User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider ) throws  IOException
{
    if ( ToXmlGenerator.class.isAssignableFrom( jsonGenerator.getClass() ) )
    {
        ToXmlGenerator xmlGenerator = ( ToXmlGenerator ) jsonGenerator;
        try
        {
            XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();
            staxWriter.writeStartElement( "lastUpdatedBy" );
            staxWriter.writeAttribute( "id", user.getUid() );
            staxWriter.writeAttribute( "name", user.getDisplayName() );
            staxWriter.writeEndElement();
        }
        catch ( XMLStreamException e )
        {
            throw new NotSerializableException( "Failed to serialize User object:" + user );
        }
    }
    else
    {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField( "id", user.getUid() );
        jsonGenerator.writeStringField( "name", user.getDisplayName() );
        jsonGenerator.writeEndObject();
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:28,代码来源:CustomLastUpdatedUserSerializer.java


示例6: transcode

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
public <T, U extends XMLStreamWriter2> U transcode(byte[] src, Class<T> srcClass, U resultWriter) throws Exception {
    try (
        JsonParser srcParser = this.objMapper.getFactory().createParser(src);
        ToXmlGenerator resultGen = this.xmlMapper.getFactory().createGenerator(resultWriter)) {
        this.xmlMapper.getSerializerProvider().initialize(resultGen, this.jaxbContextRepo.findTypeMetadata(srcClass).getQname());

        while (srcParser.nextToken() != null) {
            resultGen.copyCurrentEvent(srcParser);
        }

        return resultWriter;
    }
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:14,代码来源:XmlTranscoder.java


示例7: configureObjectMappers

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
private void configureObjectMappers()
{
    ObjectMapper[] objectMappers = new ObjectMapper[] { jsonMapper, xmlMapper };

    for ( ObjectMapper objectMapper : objectMappers )
    {
        // objectMapper.setDateFormat( format );
        objectMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL );
        objectMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false );
        objectMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false );
        objectMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false );
        objectMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true );

        objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
        objectMapper.configure( DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true );
        objectMapper.configure( DeserializationFeature.WRAP_EXCEPTIONS, true );

        objectMapper.disable( MapperFeature.AUTO_DETECT_FIELDS );
        objectMapper.disable( MapperFeature.AUTO_DETECT_CREATORS );
        objectMapper.disable( MapperFeature.AUTO_DETECT_GETTERS );
        objectMapper.disable( MapperFeature.AUTO_DETECT_SETTERS );
        objectMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS );
    }

    jsonMapper.getFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES );
    xmlMapper.configure( ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true );
}
 
开发者ID:ehatle,项目名称:AgileAlligators,代码行数:28,代码来源:DefaultRenderService.java


示例8: XmlXContentGenerator

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
public XmlXContentGenerator(ToXmlGenerator generator) {
    this.generator = generator;
    this.params = new XmlXParams();
    this.started = false;
    this.context = false;
    this.prefix = null;
    generator.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, false);
}
 
开发者ID:jprante,项目名称:elasticsearch-xml,代码行数:9,代码来源:XmlXContentGenerator.java


示例9: serialize

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
@Override
public void serialize( OrganisationUnit value, JsonGenerator jgen, SerializerProvider provider ) throws IOException
{
    if ( ToXmlGenerator.class.isAssignableFrom( jgen.getClass() ) )
    {
        ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;

        try
        {
            XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();

            staxWriter.writeStartElement( DxfNamespaces.DXF_2_0, "child" );
            staxWriter.writeAttribute( "id", value.getUid() );
            staxWriter.writeAttribute( "name", value.getName() );
            staxWriter.writeAttribute( "created", DATE_FORMAT.format( value.getCreated() ) );
            staxWriter.writeAttribute( "lastUpdated", DATE_FORMAT.format( value.getLastUpdated() ) );

            if ( value.getHref() != null )
            {
                staxWriter.writeAttribute( "href", value.getHref() );
            }

            staxWriter.writeAttribute( "hasChildren", String.valueOf( value.hasChild() ) );
            staxWriter.writeEndElement();
        }
        catch ( XMLStreamException e )
        {
            e.printStackTrace(); //TODO fix
        }
    }
    else
    {
        jgen.writeStartObject();

        jgen.writeStringField( "id", value.getUid() );
        jgen.writeStringField( "name", value.getName() );
        jgen.writeFieldName( "created" );
        provider.defaultSerializeDateValue( value.getCreated(), jgen );

        jgen.writeFieldName( "lastUpdated" );
        provider.defaultSerializeDateValue( value.getLastUpdated(), jgen );

        if ( value.getHref() != null )
        {
            jgen.writeStringField( "href", value.getHref() );
        }

        jgen.writeBooleanField( "hasChildren", value.hasChild() );

        jgen.writeEndObject();
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:53,代码来源:JacksonOrganisationUnitChildrenSerializer.java


示例10: serialize

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
@Override
public void serialize( OrganisationUnitGroup value, JsonGenerator jgen, SerializerProvider provider ) throws IOException
{
    if ( ToXmlGenerator.class.isAssignableFrom( jgen.getClass() ) )
    {
        ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;

        try
        {
            XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();

            staxWriter.writeStartElement( DxfNamespaces.DXF_2_0, "organisationUnitGroup" );
            staxWriter.writeAttribute( "id", value.getUid() );
            staxWriter.writeAttribute( "name", value.getName() );
            staxWriter.writeAttribute( "created", DATE_FORMAT.format( value.getCreated() ) );
            staxWriter.writeAttribute( "lastUpdated", DATE_FORMAT.format( value.getLastUpdated() ) );

            if ( value.getHref() != null )
            {
                staxWriter.writeAttribute( "href", value.getHref() );
            }

            staxWriter.writeAttribute( "symbol", String.valueOf( value.getSymbol() ) );
            staxWriter.writeEndElement();
        }
        catch ( XMLStreamException e )
        {
            e.printStackTrace(); //TODO fix
        }
    }
    else
    {
        jgen.writeStartObject();

        jgen.writeStringField( "id", value.getUid() );
        jgen.writeStringField( "name", value.getName() );
        jgen.writeFieldName( "created" );
        provider.defaultSerializeDateValue( value.getCreated(), jgen );

        jgen.writeFieldName( "lastUpdated" );
        provider.defaultSerializeDateValue( value.getLastUpdated(), jgen );

        if ( value.getHref() != null )
        {
            jgen.writeStringField( "href", value.getHref() );
        }

        jgen.writeStringField( "symbol", value.getSymbol() );

        jgen.writeEndObject();
    }
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:53,代码来源:JacksonOrganisationUnitGroupSymbolSerializer.java


示例11: initialize

import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; //导入依赖的package包/类
public void initialize(ToXmlGenerator gen, QName rootQname) throws IOException {
    super._initWithRootName(gen, rootQname);
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:4,代码来源:SdcctXmlMapper.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java PortProber类代码示例发布时间:2022-05-22
下一篇:
Java BytesKeyGenerator类代码示例发布时间: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