I'm stuck in splitting an array in a sub array in an object. I have the following:
Input/Output AClass:
{
attribute1: 'value1',
attribute2: 'value2',
// etc.
assets: [
{assetAttribute1: 'value1', // etc.},
{assetAttribute2: 'value2', // etc.}
// etc.
]
}
Stream Input:
inputs = [
{
attribute1: 'value1',
attribute2: 'value2',
assets: [
{assetAttribute1: 'value1', // etc.},
{assetAttribute2: 'value2', // etc.}
// etc.
]
},
]
Expected stream output:
outputs = [
{
attribute1: 'value1', // same as from the input
attribute2: 'value2', // same as from the input
assets: [
{assetAttribute1: 'value1', // etc.} // input asset array index 0
]
},
{
attribute1: 'value1', // same as from the input
attribute2: 'value2', // same as from the input
assets: [
{assetAttribute2: 'value2', // etc.} // // input asset array index 1
]
},
]
Kafka Streams code:
KStream<String, AClass> inputs = //...
KStream<String, AClass> output = inputs.map((key, aclass) -> {
return aclass.getAssets().stream().map(asset -> {
AClass transform = new AClass();
transform = aclass.clone();
transform.setAssets(Arrays.asList(asset));
return new KeyValue<String, AClass>(key, miaTransitAsset);
});
});
As you see this can not work. But I'm now stuck how I could achieve that with the Java Streams. You can ignore the Kafka stream as it basically the same.