zoukankan      html  css  js  c++  java
  • objectMapper.canSerialize SpringMVC实体转JSON字符串

    springMVC中将实体转换为json方法中,判断是否可以写入

    org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter#canWrite

    其中第173行

    this.objectMapper.canSerialize(clazz, causeRef)

    ,判断是否可以序列化指定类。

    判断是否可以序列化指定实体类.

        /**
         * Method that can be called to check whether mapper thinks
         * it could serialize an instance of given Class.
         * Check is done
         * by checking whether a serializer can be found for the type.
         *<p>
         * NOTE: since this method does NOT throw exceptions, but internal
         * processing may, caller usually has little information as to why
         * serialization would fail. If you want access to internal {@link Exception},
         * call {@link #canSerialize(Class, AtomicReference)} instead.
         *
         * @return True if mapper can find a serializer for instances of
         *  given class (potentially serializable), false otherwise (not
         *  serializable)
         */
        public boolean canSerialize(Class<?> type) {
            return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, null);
        }
    
        /**
         * Method similar to {@link #canSerialize(Class)} but that can return
         * actual {@link Throwable} that was thrown when trying to construct
         * serializer: this may be useful in figuring out what the actual problem is.
         * 
         * @since 2.3
         */
        public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
            return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, cause);
        }
    

      

  • 相关阅读:
    题解——[[SHOI2010]最小生成树]
    7.12周总结
    还有5个月就NOIP2019了,我干了什么
    【CQOI2018】破解D-H协议
    【SHOI2006】仙人掌
    【HNOI/AHOI2018】道路
    2019.11纪中集训 宋新波老师和曹天佑学长的勉励
    纪中集训2019.11.05
    【2019.10.25 OI-Killer的模拟赛】3.鸡数
    【华东师附国庆模拟赛】Day2 1.矩阵
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/12162202.html
Copyright © 2011-2022 走看看