Hi,
I'm trying to use Protostuff to deep clone object graphs. Recently I encountered a situation where I needed to clone only a subset of the entities fields (a subgraph of an entity).
I used the example from io.protostuff.runtime.FilterFieldsByGroupTest. I annotated all the fields with the correct group filter id, but it looks like the fields filtering work only for the base entity, not its sub-entities.
E.g.:
For the following entities:
public class Ent_Network{
public static final int NETWORK_CLONING_GROUP = 1;
@Tag(1)
private String code;
@Tag(value = 2, groupFilter = Ent_Network.NETWORK_CLONING_GROUP)
private Ent_NetworkType networkType;
@Tag(value = 3, groupFilter = Ent_Network.NETWORK_CLONING_GROUP)
private Set<Ent_NetworkLocation> networkLocations;
}
public class Ent_NetworkLocation {
@Tag(value = 1, groupFilter = Ent_Network.NETWORK_CLONING_GROUP)
private Ent_Network network;
@Tag(value = 2, groupFilter = Ent_Network.NETWORK_CLONING_GROUP)
private Ent_Location location;
}
public class Ent_Location {
public static final int LOCATION_CLONING_GROUP = 2;
@Tag(1)
private String code;
@Tag(value = 2, groupFilter = Ent_Location.LOCATION_CLONING_GROUP)
private Set<Ent_NetworkLocation> networkLocations;
@Tag(value = 3, groupFilter = Ent_Location.LOCATION_CLONING_GROUP)
private Set<SomeOtherEntity> someOtherEntitiesClonableOnlyFromLocation;
}
If I run the following test:
private static void testSerializationFilter(Ent_Network network){
DefaultIdStrategy primary = new DefaultIdStrategy();
DefaultIdStrategy g1 = new DefaultIdStrategy(primary, Ent_Network.NETWORK_CLONING_GROUP);
Schema<Ent_Network> schema = RuntimeSchema.getSchema(Ent_Network.class, g1);
byte[] data = ProtostuffIOUtil.toByteArray(network, schema, LinkedBuffer.allocate(256));
Ent_Network receivedNetwork = schema.newMessage();
ProtostuffIOUtil.mergeFrom(data, receivedNetwork, schema);
}
I would expect the fields networkLocations and someOtherEntitiesClonableOnlyFromLocation from Locations from the network locations to be null. Instead, they are populated. I think this happens because the groupId is not handed over to the schemas created for the subentities.
Do you have any idea on how to fix this?