File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
compiler/src/test/java/org/hisrc/jsonix/xml/bind/tests Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .hisrc .jsonix .xml .bind .tests ;
2+
3+ import java .util .Date ;
4+
5+ import javax .xml .bind .annotation .XmlAccessType ;
6+ import javax .xml .bind .annotation .XmlAccessorType ;
7+ import javax .xml .bind .annotation .XmlElement ;
8+ import javax .xml .bind .annotation .XmlRootElement ;
9+
10+ @ XmlRootElement
11+ @ XmlAccessorType (XmlAccessType .FIELD )
12+ public class BType {
13+
14+ @ XmlElement
15+ public Integer one ;
16+
17+ @ XmlElement (defaultValue = "2" )
18+ public Integer two ;
19+
20+ @ XmlElement (nillable = true )
21+ public Integer three ;
22+
23+ @ XmlElement (nillable = true , defaultValue = "4" )
24+ public Integer four ;
25+
26+ @ XmlElement
27+ public Date five ;
28+
29+ @ XmlElement
30+ public Date six ;
31+ }
Original file line number Diff line number Diff line change 11package org .hisrc .jsonix .xml .bind .tests ;
22
3+ import java .io .StringReader ;
34import java .io .StringWriter ;
45
56import javax .xml .bind .JAXBContext ;
67import javax .xml .bind .JAXBException ;
78import javax .xml .bind .Marshaller ;
9+ import javax .xml .bind .Unmarshaller ;
810
911import org .junit .Assert ;
1012import org .junit .Test ;
@@ -49,4 +51,17 @@ public void checksDefault() throws JAXBException {
4951 Assert .assertEquals ("<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" yes\" ?><aType><one></one><two>two</two><three></three><four>four</four></aType>" , sw .toString ());
5052
5153 }
54+
55+ @ Test
56+ public void checksInteger () throws JAXBException {
57+ final JAXBContext context = JAXBContext .newInstance (BType .class );
58+ final Unmarshaller unmarshaller = context .createUnmarshaller ();
59+ final String str = "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" yes\" ?><bType><one></one><two></two><three></three><four></four><five></five></bType>" ;
60+ final BType bType = (BType ) unmarshaller .unmarshal (new StringReader (str ));
61+ Assert .assertEquals (0 , bType .one .intValue ());
62+ Assert .assertEquals (2 , bType .two .intValue ());
63+ Assert .assertEquals (0 , bType .three .intValue ());
64+ Assert .assertEquals (4 , bType .four .intValue ());
65+
66+ }
5267}
You can’t perform that action at this time.
0 commit comments