简体   繁体   English

错误:com.fasterxml.jackson.databind.JsonMappingException:未找到序列化程序

[英]error: com.fasterxml.jackson.databind.JsonMappingException: No serializer found

I'm retrieving a List from bigquery job with getQueryResults and (to me) it looks like the conversion to JSON fails. 我正在使用getQueryResults从bigquery作业中检索一个列表,并且(对我而言)它似乎转换为JSON失败。 I've found this and have tried it with an annotation as follows: 我发现了这一点 ,并尝试了如下注释:

@JsonAutoDetect(fieldVisibility = Visibility.ANY)

Though without success. 虽然没有成功。

here a snippet of the code: 这是一段代码:

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.bigquery.Bigquery;
import com.google.api.services.bigquery.BigqueryScopes;
import com.google.api.services.bigquery.model.*;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)

public class Query {
    private String id;
    private String sql;
    private List<TableRow> results;

    private static Bigquery createAuthorizedClient() throws IOException {
        HttpTransport transport = new NetHttpTransport();
        JsonFactory jsonFactory = new JacksonFactory();
        GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
        // Depending on the environment that provides the default credentials (e.g. Compute Engine, App
        // Engine), the credentials may require us to specify the scopes we need explicitly.
        // Check for this case, and inject the Bigquery scope if required.
        if (credential.createScopedRequired()) {
            credential = credential.createScoped(BigqueryScopes.all());
        }

        return new Bigquery.Builder(transport, jsonFactory, credential).setApplicationName(" ...OMITTED... ").build();
    }

    public String getId() { return this.id;}
    public void setId(String id) { this.id = id; }

    public String getSql() { return this.sql; }
    public void setSql(String sql) { this.sql = sql;}

    public List<TableRow> getResults() { return this.results; }
    public void setResults(List<TableRow> r) { this.results = r; }

    public void update() {
        this.results = new ArrayList<TableRow>();
        if (!this.sql.isEmpty()){
            try {
                Bigquery bq = createAuthorizedClient();
                this.results = executeQuery(bq, this.sql);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private List<TableRow> executeQuery(Bigquery bq, String querySql) throws IOException {
        QueryResponse query = bq.jobs().query(" ...OMITTED... ", new QueryRequest().setQuery(querySql)).execute();

        // Execute it
        GetQueryResultsResponse queryResult = bq.jobs()
                .getQueryResults(query.getJobReference().getProjectId(), query.getJobReference().getJobId()).execute();

        List<TableRow> rows = queryResult.getRows();
        return rows;
    }

I'm not familiar with annotations and I don't know how to get the reply from bigquery converted to json, can somebody help? 我不熟悉注释,也不知道如何将bigquery的回复转换为json,有人可以帮忙吗?

You have to build the JSON object on your own... 您必须自己构建JSON对象...

public void update() {
    String r = "{\"rows\": [";
    List<TableRow> bqresults;
    if (!this.sql.isEmpty()){
        try {
            Bigquery bq = createAuthorizedClient();
            bqresults = executeQuery(bq, this.sql);
            int rowIx = 0;
            int rowMax = bqresults.size() - 1;
            for(TableRow row : bqresults) {
                r += row.toString();
                rowIx++;
                if (rowIx <= rowMax) r += ",";
            }
            r += "]}";
            this.results = r;  
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决com.fasterxml.jackson.databind.JsonMappingException? - How to solve the com.fasterxml.jackson.databind.JsonMappingException? 无法读取文件:N / A com.fasterxml.jackson.databind.JsonMappingException - Could not read document: N/A com.fasterxml.jackson.databind.JsonMappingException Weblogic 12.2.1.3上的com.fasterxml.jackson.databind.JsonMappingException - com.fasterxml.jackson.databind.JsonMappingException on Weblogic 12.2.1.3 com.fasterxml.jackson.databind.JsonMappingException:无限递归 - com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion com.fasterxml.jackson.databind.JsonMappingException 无法构造类的实例 - com.fasterxml.jackson.databind.JsonMappingException not able to construct instance of class com.fasterxml.jackson.databind.JsonMappingException,同时将Json转换为Object - com.fasterxml.jackson.databind.JsonMappingException while converting Json to Object Jboss 7.1 中的 com.fasterxml.jackson.databind.JsonMappingException - com.fasterxml.jackson.databind.JsonMappingException In Jboss 7.1 com.fasterxml.jackson.databind.JsonMappingException由于新的Maven条目 - com.fasterxml.jackson.databind.JsonMappingException due to new maven entries com.fasterxml.jackson.databind.JsonMappingException:无法构造实例:poja class 找不到合适的构造函数 - com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of : poja class no suitable constructor found 如何修复“com.fasterxml.jackson.databind.JsonMappingException:反序列化属性问题”错误 - How to fix 'com.fasterxml.jackson.databind.JsonMappingException: Problem deserializing property' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM