I have a gradle project. I tried gradlew clean jar and it made no changes 
to the behavior.

You can pull from here: https://github.com/ThomHehl/xlate.git and run spock 
test SourceTextConverterTest.groovy Convert. Or just ./gradlew test. This 
will create an ObadShort.xml somewhere in your build environment.

I created a unit test that seems to work fine. I have attached it if you'd 
like to commit to the repo. There doesn't seem to be a test for lists.

On Saturday, November 25, 2023 at 9:54:58 PM UTC-5 Tatu Saloranta wrote:

> On Sat, Nov 25, 2023 at 6:01 PM Tatu Saloranta <ta...@fasterxml.com> 
> wrote:
> >
> > On Sat, Nov 25, 2023 at 10:42 AM thom...@gmail.com <thom...@gmail.com> 
> wrote:
> > >
> > > Hello, again.
> > >
> > > I am trying to pull in OSIS documents and then create an OSIS 
> document. I am reading the following lines, for example:
> > >
> > > <verse osisID="Obad.1.1">
> > > <w lemma="2377" n="1.0" morph="HNcmsc" id="31xeN">חֲז֖וֹן</w>
> > > <w lemma="5662" n="1" morph="HNp" id="31Nvk">עֹֽבַדְיָ֑ה</w>
> > >
> > > here is the definition I'm using to read into:
> > >
> > > public class OsisVerse extends DocumentVerse {
> > > @JacksonXmlElementWrapper(useWrapping = false)
> > > @JacksonXmlProperty(localName = "note")
> > > private List<OsisNote> osisNotes;
> > > @JacksonXmlProperty(localName = "osisID")
> > > private String uniqueId;
> > > @JacksonXmlProperty(localName = "seg")
> > > private String segment;
> > > @JacksonXmlElementWrapper(useWrapping = false)
> > > @JacksonXmlProperty(localName = "w")
> > > private List<OsisWord> osisWords;
> > >
> > > And the deserialize seems to be working great.
> > >
> > > Now I make my changes and try to write using the same classes and I 
> get, for example:
> > >
> > > <verse><words><words id="31yNB" lemma="l/4421" morph="HRd/Ncfsa" n="0" 
> x-source-word="לַ/מִּלְחָמָֽה">(...)</words></words>
> > >
> > > So it appears that it's ignoring my annotations and serializing as it 
> feels is best.
> > >
> > > Is there a way to fix this?
> >
> > Serializer definitely should be using the same annotations, so
> > something is going on with your set up.
> > Either XmlMapper is not configured with the default XML annotation
> > introspector, or code uses something other than Jackson (if invoked
> > via framework and not directly using XmlMapper).
> >
> > If you have full reproduction (configuration and set up) maybe you can
> > either file an issue against `jackson-dataformat-xml` repo, or include
> > it here.
>
> Or probably even just
>
> ./mvnw clean compile
>
> as the plug-in is called before the compilation phase.
>
> It would be great if someone could help figure out how to improve this 
> aspect
> since it's pretty much the one FAQ about building we have.
>
> -+ Tatu +-
>
> >
> > -+ Tatu +-
> >
> > >
> > > --
> > > You received this message because you are subscribed to the Google 
> Groups "jackson-user" group.
> > > To unsubscribe from this group and stop receiving emails from it, send 
> an email to jackson-user...@googlegroups.com.
> > > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/7dc7e6f0-d381-41f9-b0f6-1f689231f10cn%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/f122d754-a767-4d76-a02a-b8917f42f101n%40googlegroups.com.
package com.fasterxml.jackson.dataformat.xml.ser;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("serial")
public class TestSerializationList extends XmlTestBase
{
    static class Sentence
    {
        @JacksonXmlProperty(isAttribute=true)
        public int numWords;

        @JacksonXmlElementWrapper(useWrapping = false)
        @JacksonXmlProperty(isAttribute = false, localName = "w")
        public List<Word> wordList;

        public Sentence(String sentenceText) {
            wordList = new ArrayList<>();

            boolean boldFlag = false;
            String[] words = sentenceText.split(" ");
            for (String myWord : words) {
                Word word = new Word();
                word.bodyText = myWord;

                word.bold  = boldFlag;
                boldFlag = !boldFlag;

                wordList.add(word);
            }

            numWords = wordList.size();;
        }
    }

    static class Word
    {
        @JacksonXmlProperty(isAttribute=true, localName="boldface")
        public boolean bold;

        @JacksonXmlText
        public String bodyText;
    }

    /*
    /**********************************************************
    /* Unit tests
    /**********************************************************
     */

    private final XmlMapper _xmlMapper = new XmlMapper();

    public void testSentence() throws IOException
    {
        String xml = _xmlMapper.writeValueAsString(new Sentence("Don't Panic!"));
        xml = removeSjsxpNamespace(xml);
        assertEquals("<Sentence numWords=\"2\"><w boldface=\"false\">Don't</w><w boldface=\"true\">Panic!</w></Sentence>", xml);
    }
}

Reply via email to