に、JavaからフォーマットされたJSONとして、私は仮定の車、飛行機などを送りたいですボートはシンプルでJavaBeansクラスであり、フィールドメンバーはjsonコントラクトをマップします。
jsonコーデックを使用してオブジェクトをJSONにシリアル化できます。たとえば、Jacksonまたはgsonを使用できます。
クラス:
class Car {
private String model;
public String getModel(){};
public void setModel(String model){...};
}
class Airplane {
private String model;
public String getModel(){};
public void setModel(String model){...};
}
class Boat {
private String model;
public String getModel(){};
public void setModel(String model){...};
}
の例では、ジャクソンと意志出力ような構造を使用します。 {"car":{"model":"xxx"},"boat":{"model":"xxx"}, ,"airplane":{"model":"xxx"}}
// Create the jsonFactory with an object mapper to serialize object to json
JsonFactory jsonFactory = new JsonFactory(new ObjectMapper());
// Create the byte array output stream
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// Create the json generator
JsonGenerator generator = jsonFactory.createGenerator(outputStream);
// Write the start object, ie. {}
generator.writeStartObject();
// Write the car "car":{}
generator.writeObjectField("car" , car);
// Write the car "boat":{}
generator.writeObjectField("boat" , boat);
// Write the car "airplane":{}
generator.writeObjectField("airplane" , airplane);
// Close the object
generator.writeEndObject();
// And the generator
generator.close();
// Convert the byte array stream to a byte array and publish the message
channel.basicPublish(outputStream.toByteArray());
あなたがたJavaBeansやラップマップは3つのクラスのコードを論文をお持ちの場合簡略化してもよい:
ObjectMapper mapper = new ObjectMapper();
byte[] bur = mapper.writeValueAsBytes(wrapper);
channel.basicPublish(outputStream.toByteArray());
最後にC#側で同じクラスを作成し、deserialize themを作成する必要があります。
java/c#generatorにjsonを使用できます。 jsonschema2pojo。