Thymeleaf inline javascript ignore null

喜欢而已 提交于 2019-12-23 17:29:07

问题


I'm using Thymeleaf to inline my very large Java Object into my HTML as a JSON:

<script th:inline="javascript">
    /*<![CDATA[*/
    var myBigObject = /*[[${myBigJavaObject}]]*/ [];
    /*]]>*/
</script>

This big Object contains a lot of null values which I don't want in my JSON since it increases the size by about 70% (~1MB).

For Spring MVC Jackson serialization I successfully use the following annotation on my model classes to automatically remove all null values in my web-service JSON responses:

@JsonInclude(JsonInclude.Include.NON_NULL)

However this annotation has no effect on Thymeleaf Javascript inline serialization.

How do I easily get rid of my null values with Thymeleaf Javascript inline serialization?

Side question: I feel this should be a major issue for a lot of people, yet the only SO issue I could find was this: theymeleaf inline javascript framework issue which is very old. Am I asking the wrong question or is it so rare for people to want to clean their inlined JS of null values when using Thymeleaf?

来源:https://stackoverflow.com/questions/33821081/thymeleaf-inline-javascript-ignore-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!