java - JAXB what should be returned from `beforeMarshal(Marshaller)` method? -


first of all, i'm not talking marshaller#listener. i'm talking class defined event callbacks.

can tell me should returned boolean beforemarshal(marshaller) method?

/**  * apidocs method?  * should return this?  */ boolean beforemarshal(marshaller marshaller); 

i mean, anyway, use method converting jpa's long @id jaxb's string @xmlid with jaxb-ri , without moxy.

[edited] void version seems working though. documentation problem?

short answer

the boolean return type documentation error. return type should void.

long answer

i mean, anyway, use method converting jpa's long @id jaxb's string @xmlid

you use eclipselink jaxb (moxy) not have restriction field/property annotated @xmlid of type string.

with jaxb-ri , without moxy.

you use xmladapter map support use case:

idadapter

this xmladapter converts long value string value meet requirements of @xmlid annotation.

package forum9629948;  import javax.xml.bind.datatypeconverter; import javax.xml.bind.annotation.adapters.xmladapter;  public class idadapter extends xmladapter<string, long> {      @override     public long unmarshal(string string) throws exception {         return datatypeconverter.parselong(string);     }      @override     public string marshal(long value) throws exception {         return datatypeconverter.printlong(value);     }  } 

b

the @xmljavatypeadapter annotation used specify xmladapter:

package forum9629948;  import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.xmljavatypeadapter;  @xmlaccessortype(xmlaccesstype.field) public class b {      @xmlattribute     @xmlid     @xmljavatypeadapter(idadapter.class)     private long id;  } 

a

package forum9629948;  import javax.xml.bind.annotation.*;  @xmlrootelement @xmlaccessortype(xmlaccesstype.field) public class {      private b b;     private c c;  } 

c

package forum9629948;  import javax.xml.bind.annotation.*;  @xmlaccessortype(xmlaccesstype.field)public class c {      @xmlattribute     @xmlidref     private b b;  } 

demo

package forum9629948;  import java.io.file; import javax.xml.bind.*;  public class demo {      public static void main(string[] args) throws exception {         jaxbcontext jc = jaxbcontext.newinstance(a.class);          file xml = new file("src/forum9629948/input.xml");         unmarshaller unmarshaller = jc.createunmarshaller();         a = (a) unmarshaller.unmarshal(xml);          marshaller marshaller = jc.createmarshaller();         marshaller.setproperty(marshaller.jaxb_formatted_output, true);         marshaller.marshal(a, system.out);     }  } 

input/output

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <a>     <b id="123"/>     <c b="123"/> </a> 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -