users@jaxb.java.net

Re: mapping attributes java.lang.Character

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Mon, 2 Mar 2009 17:16:26 +0100

That's for the class where your tipo element occurs:

    @XmlElement(name = "Tipo", required = true)
    @XmlJavaTypeAdapter(AdapterTipo.class)
    protected Character tipo;
    public Character getTipo() {
        return tipo;
    }
    public void setTipo(Character tipo) {
        this.tipo = tipo;
    }

Then you'll need this class, in the same package (or you'll have
the class entry in the annotation):

import javax.xml.bind.annotation.adapters.XmlAdapter;
public class AdapterTipo extends XmlAdapter<String,Character>{
    public Character unmarshal(String value) {
        return value.charAt( 0 );
    }
    public String marshal(Character value) {
        return String.valueOf( value );
    }
}

That's all.
-W


On Mon, Mar 2, 2009 at 4:07 PM, Lucas Eskopinski <eskopinski_at_gmail.com>wrote:

>
> me too. I can't change the mapping of Character to String in hibernate
> column, because firebird column is CHAR;
>
> Thanks.
>
>
> Wolfgang Laun-2 wrote:
> >
> > Well, then use String instead of char.
> >
> > I don't think it's worth fussing with a type adapter...
> >
> > -W
> >
> > On Mon, Mar 2, 2009 at 3:50 PM, Lucas Eskopinski
> > <eskopinski_at_gmail.com>wrote:
> >
> >>
> >> Yes, this was exactly the call.
> >>
> >> fone.setTipo('O');
> >>
> >> The class I generated manually...
> >>
> >>
> >> Wolfgang Laun-2 wrote:
> >> >
> >> > If you generate Java code from the XML schema you've posted you'd get
> >> > a String as the type for Tipo. How did you obtain the annotated Java
> >> code?
> >> >
> >> > Did you call
> >> > setTipo( 'O' ) // upper case 'o'
> >> >
> >> > That would explain "79" being marshalled.
> >> >
> >> > -W
> >> >
> >> >
> >> >
> >> > On Mon, Mar 2, 2009 at 2:42 PM, Lucas Eskopinski
> >> > <eskopinski_at_gmail.com>wrote:
> >> >
> >> >>
> >> >> I’m having the problem, I would like to find a solution ;).
> >> >>
> >> >> javax.xml.bind.MarshalException
> >> >> - with linked exception:
> >> >> [org.xml.sax.SAXParseException: cvc-length-valid: Value '79' with
> >> length
> >> >> =
> >> >> '2' is not facet-valid with respect to length '1' for type
> >> >> '#AnonType_TipoTelefoneType'.]
> >> >> at
> >> >>
> >> >>
> >>
> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:304)
> >> >> at
> >> >>
> >> >>
> >>
> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:230)
> >> >> at
> >> >>
> >> >>
> >>
> javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:96)
> >> >>
> >> >>
> >> >> @XmlElement(name = "Tipo", required = true)
> >> >> public Character getTipo() {
> >> >> return telefone.getTipo();
> >> >> }
> >> >>
> >> >> public void setTipo(Character tipo) {
> >> >> this.telefone.setTipo(tipo);
> >> >> }
> >> >>
> >> >>
> >> >> <xs:element name="Tipo">
> >> >> <xs:simpleType>
> >> >> <xs:restriction base="xs:string">
> >> >> <xs:length value="1"/>
> >> >> </xs:restriction>
> >> >> </xs:simpleType>
> >> >> </xs:element>
> >> >>
> >> >> Any help appreciated,
> >> >> Lucas.
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://www.nabble.com/mapping-attributes-java.lang.Character-tp22288321p22288321.html
> >> >> Sent from the java.net - jaxb users mailing list archive at
> >> Nabble.com.
> >> >>
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> >> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >> >>
> >> >>
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/mapping-attributes-java.lang.Character-tp22288321p22289519.html
> >> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> >> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/mapping-attributes-java.lang.Character-tp22288321p22289821.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>