我有類似下面的類:如何發佈jsonstring如REST類型的請求郵遞員
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.springframework.util.StringUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@Data
public class MyTestClass {
@JsonProperty("first")
private List<String> first = new ArrayList<>();
@JsonProperty("second")
private List<String> second = new ArrayList<>();
@JsonProperty("third")
private List<String> third = new ArrayList<>();
public static MyTestClass emptyFilter() {
return new MyTestClass();
}
@SuppressWarnings("unused") //JSR311
@Nonnull
public static MyTestClass fromString(@Nullable String jsonString) {
if (StringUtils.isEmpty(jsonString)){
return emptyFilter();
}
return JsonUtils.fromJSONString(jsonString, MyTestClass.class, false);
}
}
我的問題是關於問題的REST調用Web服務的輸入。我的請求必須有一個filter
參數,這個參數應該是指這個類。所以,我拿什麼作爲過濾參數是這樣的:
{"MyTestClass":{"first":[],"second":[],"third":[]}}
但我總是得到這樣的錯誤:
Failed to convert value of type 'java.lang.String' to required type 'MyTestClass'
我新的Spring框架和我的問題可能是愚蠢的:
我知道過濾器參數應該是
jsonObject
,其中包括三個JsonArray
s。jsonObject
內的主要參數名稱應該是什麼,其中包括JsonArray
s。正如你所看到的,我使用了類名。那是對的嗎?如果我已經從stackoverflow
的其他問題中正確地理解了它,那麼當我使用基於Spring
編寫的類時,應該使用這個。如果不正確,我該如何找到應該調用的內容?我可以簡單地通過查看課程來看到
jsonArray
的名稱,因爲它們是課程的變量。但是包含所有這些數組的jsonObject
的名稱怎麼樣?從這個類看來,類似乎還必須接受空字符串作爲過濾器。但我也嘗試過,並且不起作用。我應該在哪裏尋找問題?
我還要提到的是我的工作是在一家公司,這是一個非常大的項目,該項目最近已被轉換爲Spring框架的一小部分,我們正在測試,如果一切工作了。
什麼庫是JsonUtils。我沒有看到它的導入 –