Hi all;
XmlFormat.printToString is OK, but when back, de-serialize, the
following exceptions occur, this is just a very simple protobu
object, picked it up from
http://code.google.com/apis/protocolbuffers/docs/javatutorial.html.
Questions:
1. If any wrong on my invoking method, please let me know, thanks.
XML:
<Person><name>John Doe</name><id>1234</id><email>
jd...@example.com</
email><phone><number>555-4321</number><type>HOME</type></phone></
Person>
Exception in thread "main" com.googlecode.protobuf.format.XmlFormat
$ParseException: 1:63: Expected ">".
at com.googlecode.protobuf.format.XmlFormat
$Tokenizer.parseException(XmlFormat.java:668)
at com.googlecode.protobuf.format.XmlFormat
$Tokenizer.consume(XmlFormat.java:467)
at
com.googlecode.protobuf.format.XmlFormat.consumeClosingElement(XmlFormat.java:
791)
at com.googlecode.protobuf.format.XmlFormat.mergeField(XmlFormat.java:
875)
at com.googlecode.protobuf.format.XmlFormat.merge(XmlFormat.java:774)
at com.googlecode.protobuf.format.XmlFormat.merge(XmlFormat.java:722)
at HelloWorldApp.main(HelloWorldApp.java:54)
import com.googlecode.protobuf.format.XmlFormat;
import com.googlecode.protobuf.format.XmlFormat.ParseException;
class HelloWorldApp {
public static void main(String[] args) throws ParseException {
TestPerson.Person john =
TestPerson.Person.newBuilder()
.setId(1234)
.setName("John Doe")
.setEmail("
jd...@example.com")
.addPhone(
TestPerson.Person.PhoneNumber.newBuilder()
.setNumber("555-4321")
.setType(TestPerson.Person.PhoneType.HOME))
.build();
String xmlFormatJohn = XmlFormat.printToString(john);
System.out.println("XML:\n" + xmlFormatJohn);
TestPerson.Person.Builder builder =
TestPerson.Person.newBuilder();
XmlFormat.merge(xmlFormatJohn, builder);
}
}