Java Protobuf Serialization

Active1 year, 5 months ago
  1. Java Protobuf Serialization Error
  2. Java Protobuf Serialize To String
  3. Java Protobuf Serialization File
  4. Protobuf Java Tutorial
  5. Java Protobuf Serialize To String
Java protobuf serialization tutorial

In Java, the package name is used as the Java package unless you have explicitly specified a javapackage, as we have here. Even if you do provide a javapackage, you should still define a normal package as well to avoid name collisions in the Protocol Buffers name space as well as in non-Java languages.

What needs to be done in order to serialize enums with protobuf-net? I'm getting the below error when serializing a class having an enum property, if the DataMember attribute is removed from the property declaration it works fine.

'System.InvalidOperationException: Onlytrue'>77 gold badges43 silver badges74 bronze badges

2 Answers

I suspect they are actually 2 different scenarios, but with regard to the code sample added by Andrew, this is because it can't figure out (in advance) what it is going to do with regards to default values (by default, data is treated as optional at the receiver). There are 3 ways of fixing this:

1: add an enum with value 0 (since 0 is always the CLI default value for zeros), for example

2: tell it which value to use by default:

3: tell the engine that it really doesn't need to worry about it, i.e. that it is going to have a value:

Marc Gravell

Java Protobuf Serialization Error

Marc Gravell
824k213 gold badges2227 silver badges2624 bronze badges
Andrew KalashnikovAndrew Kalashnikov
1,2903 gold badges24 silver badges53 bronze badges

Not the answer you're looking for? Browse other questions tagged enumsprotocol-buffersprotobuf-net or ask your own question.

A java serialization library with built-in support for forward-backward compatibility (schema evolution) and validation.

  • efficient, both in speed and memory
  • flexible, supporting pluggable formats

Java Protobuf Serialize To String

Usecase

Serialize

Java Protobuf Serialization File

  • messaging layer in RPC
  • storage format in the datastore or cache

For more information, go to https://protostuff.github.io/docs/

Usage

Maven

  1. When you generate schemas for your classes
  1. Runtime schemas

Questions/Concerns/Suggestions

  • subscribe to http://groups.google.com/group/protostuff/

Requirements

Java 1.6 or higher

Build Requirements

Protobuf Java Tutorial

Maven 3.2.3 or higher

Java Protobuf Serialize To String

Developing with eclipse