为什么每次我购买自己的假装解码器时都回退?

问题描述

    public class MicroShopDecode implements Decoder {
    
        private final ObjectMapper objectMapper;
    
        public MicroShopDecode(ObjectMapper objectMapper) {
            this.objectMapper = objectMapper;
        }
    
    
        @Override
        public Object decode(Response response,Type type) throws IOException,DecodeException,FeignException {
    
            if (response.status() == 404) {
                return Util.emptyValueOf(type);
            }
            if (response.body() == null) {
                return null;
            }
            Reader reader = response.body().asReader();
            if (!reader.markSupported()) {
                reader = new BufferedReader(reader,1);
            }
            try {
                // Read the first byte to see if we have any data
                reader.mark(1);
                if (reader.read() == -1) {
                    return null;
                    // Eagerly returning null avoids "No content to map due to end-of-input"
                }
                reader.reset();
    
                JsonNode node = objectMapper.readTree(reader);
    
    
                int errcode = node.get("errcode").asInt();
                int total_num = node.get("total_num").asInt();
                String errmsg = null;
                if (node.has("orders")){
    //          doSomething
                    JsonNode orders = node.get("orders");
                    String content = orders.toString();
    
                    List<MicroShopOrder> list = objectMapper.readValue(content,List.class);
                    MicroShopResponseRoot<MicroShopOrder> microShopOrderMicroShopResponseRoot = new MicroShopResponseRoot<>(errcode,list,total_num,errmsg);
                    return microShopOrderMicroShopResponseRoot;
                }
                if (node.has("spus")) {
                    List<MicroShopSpu> list = new ObjectMapper().readValue(node.get("orders").textValue(),List.class);
                    return new MicroShopResponseRoot<>(errcode,errmsg);
                }
    
            } catch (RuntimeJsonMappingException e) {
                if (e.getCause() != null && e.getCause() instanceof IOException) {
                    throw IOException.class.cast(e.getCause());
                }
                throw e;
            }
            return null;
        }
    }
我想以自己的方式解码json(“ orders”也解码为MicroShopRoot.data列,“ spu”也是如此),所以我在假装客户端中使用配置。 当运行到“ objmapper.readValue()”时,假装会回退,idont konw为什么,如果你们有什么想法,请告诉我,谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)