0
Spring Javaアプリケーションでは、次の入力でREST json要求を受け取ります。ここで、 'mode'フィールドはJavaクラスのbyteとして定義されています。json Stringから型byteの値を逆シリアル化できません。
{
"application": "sadsd",
"date": "20161109",
"mode": "A",
"catalogId": 0,
}
POJO -
public class Test {
String application;
String date;
byte mode;
int catalogId;
...
}
以下のエラー取得 -
"exception": org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Could not read document: Can not deserialize value of type byte from String \"A\":
not a valid Byte value\n at
[Source: [email protected]; line: xx, column: xx]
(through reference chain: com.abc.myInput[\"mode\"]);
`enter code here`nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException:
Can not deserialize value of type byte from String \"A\":
not a valid Byte value\n at [Source: [email protected]; line: xx, column: xx]
(through reference chain: com.abc.myInput[\"mode\"])",`
を私はここにシリアライザとデシリアライザを記述する必要がありますか?
追加のコードを書き込まずに、そのフィールドのバイトフィールドまたはget/setメソッドで使用できるアノテーションはありますか?
モデルで文字列変数を使用できないのはなぜですか? JSONにはバイト配列の概念がありません。バイト配列を使用するためにStringクラスのコンストラクタを使用するセッターとゲッターを書くことができます –
モデルが生成され、他の多くのものによって使用されるので、データ型の変更はオプションではありません。 – chappalprasad
それからカスタムデシリアライザが必要です。 –