Comments (7)
Thanks for the response @fax4ever,
Yeah, the main question is how to add annotations to Animal
and its concrete subclasses. As I mentioned, the above example with @AutoProtoSchemaBuilder
fails to compile saying the @protofield type "should not be abstract".
abstract class Animal {
String type;
}
class Dog extends Animal {
String name;
void bark();
// ...
}
from protostream.
Yes! One-of seems to be the proper way to map the polymorphism.
At the moment I think that we don't support the schema generation for this case with @AutoProtoSchemaBuilder
.
I'm opening an issue for it to the ProtoStream Jira => https://issues.redhat.com/projects/IPROTO.
In the meantime I think you could generate the mashallers and the proto schema manually, as we used to do.
from protostream.
Hi @srpn,
Exactly the idea of the ProtoAdapter
is to generate the marshallers and the schema for class we cannot modify.
I think that you need to set the number attribute in the @ProtoField
annotation.
from protostream.
Moreover, you should annotate the class Animal
with the @ProtoField
s or define a ProtoAdapter for it in turn.
Can you share more about Animal
please?
from protostream.
What would be the Protocol Buffers schema you would like to generate for this case?
from protostream.
I am looking to use Infinispan for a distributed cache and I am new to Protocol Buffers.
From what I read, oneOf
could be a way to represent this as a protobuf message
Here is a full example for ease of reproducing
error: org.infinispan.protostream.annotations.ProtoSchemaBuilderException: The type com.test.Animal of field 'animal' of com.test.CachedAnimalAdapter should not be abstract.
Code used:
package com.test;
import org.infinispan.protostream.annotations.ProtoAdapter;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
@ProtoAdapter(CachedAnimal.class)
public class CachedAnimalAdapter {
@ProtoFactory
CachedAnimal create(Animal animal, String cacheDuration) {
return new CachedAnimal(animal, cacheDuration);
}
@ProtoField(number = 1)
Animal getAnimal(CachedAnimal cachedAnimal) {
return cachedAnimal.getAnimal();
}
@ProtoField(number = 2)
String getCacheDuration(CachedAnimal cachedAnimal) {
return cachedAnimal.getCachedTime();
}
}
// Let's say the below classes are from a 3rd party library that I cannot annotate
class CachedAnimal {
private Animal animal;
private String cachedTime;
public CachedAnimal(Animal animal, String cachedTime) {
this.animal = animal;
this.cachedTime = cachedTime;
}
public Animal getAnimal() {
return animal;
}
public String getCachedTime() {
return cachedTime;
}
}
abstract class Animal {
String type;
public Animal(String type) {
this.type = type;
}
}
class Dog extends Animal {
private String breed;
public Dog(String type, String breed) {
super(type);
this.breed = breed;
}
public void makeSound() {
System.out.println("woof");
}
}
class Cat extends Animal {
private String name;
public Cat(String type, String name) {
super(type);
this.name = name;
}
public void makeSound() {
System.out.println("meow");
}
}
from protostream.
created https://issues.redhat.com/browse/IPROTO-267
from protostream.
Related Issues (10)
- Support for generic marshallers HOT 3
- ObjectArrayAdapter generating marshaller in java.lang HOT 4
- ProtoReserved statements always commented in proto file HOT 1
- Compilation error "@ProtoAdapter can only be applied to classes" on enum HOT 5
- Protobuf encoding marshling is not working when in a Java collection is used in the value part of the map
- Use ByteBuddy instead of Javassist HOT 1
- Caused by: org.infinispan.protostream.AnnotationParserException: Error: 1,43: illegal escape character: u HOT 2
- Standalone usage HOT 1
- java.lang.NoClassDefFoundError: ProtoSchema - v5.0.1.Final HOT 23
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protostream.