问题
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