I have a json String and it needs to be converted to Optional data type.
Getting Optional.empty as the response. Is it possible to get the Optional here with the correct value.
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.sams.interceptor.model.mixins.HttpStatusMixIn;
import com.sams.interceptor.model.mixins.ResponseEntityMixin;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.io.IOException;
import java.util.Optional;
public class App2 {
public static void main(String[] args) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
String jsonStr = "{\"value\":{\"id\":123}}";
Optional<Student> abc = objectMapper.readValue(jsonStr,java.util.Optional.class);
System.out.println(abc);
}
}
class Student {
int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}