XmlFormat.merge, parse exceptions, need help.

121 views
Skip to first unread message

jianhua

unread,
Jul 10, 2011, 10:57:30 PM7/10/11
to protobuf-java-format
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);
}
}

Huzza

unread,
Jul 12, 2011, 9:57:43 PM7/12/11
to protobuf-java-format
I have modified the XmlFormat code to fix that bug. But I don't how to
commit the code.
Is this project mainainted?

On 7月11日, 上午10时57分, jianhua <yujianhua2...@gmail.com> wrote:
> 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 fromhttp://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>j...@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.ja va:
> 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("j...@example.com")

Jeffrey Damick

unread,
Aug 29, 2011, 9:54:20 AM8/29/11
to protobuf-java-format
Did you open an issue and attach the patch? If not, would you please.
Reply all
Reply to author
Forward
0 new messages