com.google.common.base.Optional中是否有Json串行器/解串器?JSON:序列化番石榴可選
開箱這似乎並沒有與傑克遜合作的,見下圖:
package com.example;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import com.google.common.base.Optional;
public class TestClass {
public Optional<String> myString;
public TestClass() {
myString = Optional.of("testString");
}
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
TestClass testClass = new TestClass();
ObjectMapper objectMapper = new ObjectMapper();
String jsonString = objectMapper.writeValueAsString(testClass);
System.out.println(jsonString);
}
}
- > { 「的myString」:{ 「禮物」:真正}}
您能否提供異常堆棧跟蹤? –
也沒有例外。輸出的序列化是{「myString」:{「present」:true}} 但是,我錯過了字符串的實際值 – Hansi