on 05-27-2015 11:19 AM
Hi All,
I am very new to Java mapping and working on the same for replacing the few strings with some data.
but when i tried to test that mapping, i am facing below exception.
below is the java code which i am using..
package com.javaMapping;
import java.io.*;
import com.sap.aii.mapping.api.*;
public class WellformedXML_JavaMapping extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
try {
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
String inputContent = new String(b);
String[] originalvalue={"{\"ns0:WasteTransferNote\" :",", {}","\"WasteStreamCodes\" :",", \"Dummy1\" : \"1\"","\"TrackingNumbers\" :",", \"Dummy2\" : \"2\"",", \"Dummy3\" : \"3\"}"};
String[] replacedvalue={"","","\"WasteStreamCodes\" : [","]","“TrackingNumbers” : [","]",""};
for(int i=0;i<originalvalue.length;i++){
inputContent = inputContent.replaceAll(originalvalue[i], replacedvalue[i]);
}
outputstream.write(inputContent.getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
input mgs coming like below:
{"ns0:WasteTransferNote" : { "field1": null, "field2": "ec92a1e9-cef0-48aa-8800-a2e500ce8b1c", "field3": null, "Subnode": [ { "field4": 80, "field5":"Kilograms", "field6": null, "field7": "12345678-0003-0000-0000-000000000012", "field8": null, "field9": "DFF5JGJ3N5", "WasteStreamCodes": "200301"
},{} ]}}
Can anyone please help me why that exception coming?
Thanks & Regards,
Maheswarareddy
Hi Maheswarareddy,
The symbol { is a reserved character for regex. You should escape it with \\{
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.