Java で JAX-RS を使用して実装されている残りの API に、次の utf-8 でエンコードされた XML を送信しようとしています。
XML データ:
<?xml version="1.0" encoding="UTF-8"?>
<incomingData><Text>καλημέρα</Text></incomingData>
次に、次の REST API 呼び出しを使用してデータを解析しようとしています。
@PUT()
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.TEXT_XML)
public void print(@QueryParam("printerID") int printerID,
InputStream requestBodyStream) {
IncomingData StudentData = null;
try {
JAXBContext jaxbContext =
JAXBContext.newInstance(IncomingData.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
StudentData = (IncomingData) jaxbUnmarshaller.unmarshal(requestBodyStream);
} catch (JAXBException e) {
e.printStackTrace();
}
try {
System.out.println(new String(StudentData.Text.getBytes(), "UTF-8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
XML コンテンツを簡単に解析するために、次の JAXB アノテーション付きクラスも使用しています。
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class IncomingData {
@XmlElement(name = "Text")
String Text = new String();
}
ただし、Text
XML タグの内容は、その内容を?????
UTF-8 でエンコードされた文字列として印刷しているときと同じように表示されます。
どうすれば問題を解決できますか?