com.fasterxml.jackson.databind.runtimejsonmappingexception:没有int/int参数构造函数/工厂方法从数值反序列化

q7solyqu  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(284)

我一直在尝试将json对象读入我的pojo。但是得到以下错误

com.fasterxml.jackson.databind.RuntimeJsonMappingException: Can not construct instance of com.a9.ao.recency.aaxlogs.pojos.AAXImpressionLogView: no int/Int-argument constructor/factory method to deserialize from Number value (29)

我的pojo课

package com.a9.ao.recency.aaxlogs.pojos;

import com.a9.ao.recency.constants.ViewabilityFeatureConstants;
import com.a9.ao.recency.misc.utility.AAXLogUtils;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyClass {

    @JsonProperty("sourceId")
    private String sourceId;

    @JsonProperty("bidId")
    private String bidId;

    @JsonProperty("bidderCategory")
    private String bidderCategory;

    @JsonProperty("userAgentInfo")
    private JsonNode userAgentInfoNode;

    @JsonProperty("sourceInfo")
    private JsonNode sourceInfoNode;

    @JsonProperty("responseMediaType")
    private String responseMediaType;

    @JsonProperty("impressionTime")
    private String impressionTime;

    @JsonProperty("zone")
    private String zone;
}

我得到这个错误的逻辑:

final MappingIterator<Object> iterator = objReader.readValues(s3Stream); //s3stream is of InputStream type, and is a stream of s3 object

        int lineCount = 0;
        while (iterator.hasNextValue()) {
            final MyClass logView = (MyClass) iterator.next();//This is the line throwing exception
            //Hook for processing a log-view
            ++lineCount;
        }

我尝试将s3中的输入流转换为字符串,并且使用相同的代码,它是这样工作的。添加示例供参考,不确定有什么问题,可以请任何人帮忙。

String str1 = IOUtils.toString(s3Stream, StandardCharsets.UTF_8);
InputStream stream = new ByteArrayInputStream(str1.getBytes(StandardCharsets.UTF_8));
            ObjectReader objectReader = objectMapper.readerFor(MyClass.class);
            final MappingIterator<Object> iterator = objectReader.readValues(stream);
            while(iterator.hasNextValue()){
                MyClass p =(MyClass) iterator.next();//Works fine
            }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题