Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "optionChain" (class com.thompson.OptionsImpliedMovement.data.OptionChain), not marked as ignorable (one known property: "result"])
at [Source: (String)"{"optionChain":{"result":[{"underlyingSymbol":"KO","expirationDates":[1550188800,1550793600,1551398400,1552003200,1552608000,1553212800,1553817600,1555545600,1558051200,1561075200,1565913600,1579219200,1610668800],"strikes":[37.0,38.0,40.5,41.5,42.5,43.5,44.5,45.5,46.5,47.5,48.5,49.5,50.5,51.0,51.5,52.0,53.0,53.5,54.0],"hasMiniOptions":false,"quote":{"language":"en-US","region":"US","quoteType":"EQUITY","quoteSourceName":"Nasdaq Real Time Price","currency":"USD","exchangeDataDelayedBy":0,"earnin"[truncated 10817 chars]; line: 1, column: 17] (through reference chain: com.thompson.OptionsImpliedMovement.data.OptionChain["optionChain"])
这里是主类,pop.xml,以及我的两个Java类:
主要内容:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thompson.OptionsImpliedMovement.data.OptionChain;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
@SpringBootApplication
public class OptionsImpliedMovementApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(OptionsImpliedMovementApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
String resourceURL = "https://query2.finance.yahoo.com/v7/finance/options/ko";
HttpEntity entity = new HttpEntity<>(headers);
ResponseEntity response = restTemplate.exchange(resourceURL, HttpMethod.GET,entity, String.class);
String rawJson = response.getBody();
ObjectMapper objectMapper = new ObjectMapper();
OptionChain optionChain = objectMapper.readValue(rawJson, OptionChain.class);
}
}
xml·
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.2.RELEASE
com.thompson
OptionsImpliedMovement
0.0.1-SNAPSHOT
OptionsImpliedMovement
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
org.springframework
spring-web
org.springframework
spring-webmvc
com.fasterxml.jackson.core
jackson-databind
org.springframework.boot
spring-boot-maven-plugin
选项链:
import com.fasterxml.jackson.annotation.JsonProperty;
public class OptionChain {
@JsonProperty("result")
public Result result;
}
结果:
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Result {
@JsonProperty("underlyingSymbol")
public String symbol;
@JsonProperty("expirationDates")
public long[] expirationDates;
@JsonProperty("strikes")
public double[] strikes;
@JsonProperty("hasMiniOptions")
public boolean hasMiniOptions;
@JsonProperty("quote")
public Quote quote;
@JsonProperty("options")
public Options option;
}
以下是
提前感谢您的帮助!