1

I want to show the maxLength property in the below XML code. What i need to in my java class.

JAVA Class need to modified occording the below xml:

public class xxxx{
 protected String directionsToSite;
}

===========================================================
XML Expected will be like this:

  <element name="accessToAntennas" minOccurs="0">
            <simpleType>
             <restriction base="{http://www.w3.org/2001/XMLSchema}string">
               <maxLength value="500"/>
            <restriction>
           <simpleType>
         </element>
Rajabaskar
  • 11
  • 2

1 Answers1

0

Try using the annotation @Size(min=..., max=...) Or you can try :

public class TheClazz {
  @XmlJavaTypeAdapter(value = MyXmlAdapter.class, type = String.class)
  private String myString;
}

public class MyXmlAdapter extends XmlAdapter<String, String> {

    private final int MAX = 500; 

    @Override
    public String unmarshal(String s) throws Exception {
        return s.size() > MAX ? throw new Exception() : s; 
    }

    @Override
    public String marshal(String s) throws Exception {
        return s.substring(0, MAX);
    }
}
Zorglube
  • 431
  • 5
  • 14