Protostream-processor: marshalling List of List

148 views
Skip to first unread message

Simone Di Cola

unread,
May 21, 2021, 11:59:44 AM5/21/21
to Protocol Buffers

````quote
I have the following field 
```
public List<List<String>> data;
```

That I need to serialise using protobuf (for infinispan-client).

I am trying to annotate the getter this way
```
    @ProtoField(number = 6)
    public List<List<String>> getData() {
        return data;
    }
```
But I got:
```
org.infinispan.protostream.annotations.ProtoSchemaBuilderException: The type java.util.List of field 'data' of xyz.property.data.model.GrowthStats should not be abstract.
```

Hence I created another class called Data:
```
@Setter
@EqualsAndHashCode
public class Data {

    List<String> stats;

    @ProtoField(number = 1, collectionImplementation = ArrayList.class)
    public List<String> getStats() {
        return stats;
    }
}
```
and modified the main class this way:

```
    public List<Data> data;

    @ProtoField(number = 6, collectionImplementation = ArrayList.class)
    public List<Data> getData() {
        return data;
    }
```
And I created this:
```
@AutoProtoSchemaBuilder(includeClasses = {GrowthStats.class, Data.class}, schemaPackageName = "stats.data.xyz.property")
public interface GrowthContextInitializer extends SerializationContextInitializer {
}
```
````

Simone Di Cola

unread,
May 21, 2021, 12:05:15 PM5/21/21
to Protocol Buffers
Here the Json example I need to Marshal:

{ "status": "success", "postcode": "W14", "postcode_type": "district", "url": "https://propertydata.co.uk/draw?input=W14", "data": [ [ "Aug 2013", 862199, null ], [ "Aug 2014", 1039052, "20.5%" ], [ "Aug 2015", 1069005, "2.9%" ], [ "Aug 2016", 1077210, "0.8%" ], [ "Aug 2017", 1123564, "4.3%" ], [ "Aug 2018", 1109593, "-1.2%" ] ], "process_time": "0.57" }

and here the Pojo:

@Setter
@EqualsAndHashCode
public class GrowthStats {
public String status;
public String postcode;
public String postcode_type;
public Long effective_date;
public String url;

public List<List<String>> data;
public String process_time;

@ProtoField(number = 1)
public String getStatus() {
return status;
}

@ProtoField(number = 2)
public String getPostcode() {
return postcode;
}

@ProtoField(number = 3)
public String getPostcode_type() {
return postcode_type;
}

@ProtoField(number = 4)
public Long getEffective_date() {
return effective_date;
}

@ProtoField(number = 5)
public String getUrl() {
return url;

}

@ProtoField(number = 6)
public List<List<String>> getData() {
return data;
}

@ProtoField(number = 7)
public String getProcess_time() {
return process_time;
}
}

Reply all
Reply to author
Forward
0 new messages