Bootstrap

SAP PI/PO java mapping

PI/PO Java Mapping

讲解:xml转json,特殊json串


技术:SAP、XI/PI/PO、JAVA、XML、JSON


前言

说明:需导入额外的jar包org.json:PO标准无法转的JSON串此方法都可转

org.json下载: https://mvnrepository.com/artifact/org.json/json


提示:以下内容仅供参考,有问题可留言

一、下载org.json并导入ESB

示例:ESB Imported Archive

二、创建java映射类

1.引入库

代码如下(示例):

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.XML;

import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;

2.处理流程

代码如下(示例):

public class ZC01 extends AbstractTransformation {
   

	public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
   
		this.execute(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
	}

	public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException {
   
		AbstractTrace trace = (AbstractTrace) getTrace();
		try {
   
			String output = "";
			String fileContent = "";
			BufferedReader reader = new BufferedReader(new InputStreamReader(arg0));
			StringBuilder out = new StringBuilder();
			String line = reader.readLine();
			while (line !=<
;