How to use constants in XML for XStream

lorimi

New Member
Please, how to define java constant like Integer.MAX_VALUE in XML? I know how to use enum, but I have third-party library and have to operate with constants.E.g. in xml file exists some value and I would like that in generated java class should be declared as constant.XML:\[code\] <person> <firstname>Joe</firstname> <lastname>Walnes</lastname> <phone> <code>123</code> <number>1234-456</number> </phone> <fax> <code>123</code> <number>9999-999</number> </fax> </person>\[/code\]Java:\[code\] public class Person { private String firstname; private String lastname; private PhoneNumber phone; private PhoneNumber fax; // ... constructors and methods}public class PhoneNumber {private int code;private String number;// ... constructors and methods } \[/code\]This works. But should be like:XML:\[code\] <person> <firstname>Joe</firstname> <lastname>Walnes</lastname> <phone> **<const>**PnoneNumber.LOCAL**</const>** </phone> <fax> <code>123</code> <number>9999-999</number> </fax> </person>\[/code\]Java should be:\[code\] public class Person { private String firstname; private String lastname; private PhoneNumber phone; private PhoneNumber fax; // ... constructors and methods}public class PhoneNumber {public static final PnoneNumber LOCAL=new PhoneNumber(123,"1234-456");private int code;private String number;// ... constructors and methods }\[/code\]Can I do it in easy way and without a custom converter?Thanks a lot.
 
Back
Top