jackson - Evaluate JSon with null value using Freemarker -


when dealing json values null freemarker give error in ?eval.

with mapper.setserializationinclusion(inclusion.non_null) can avoid miss information on generated json.

there's way achieve evaluation null values?

<#assign test = "{\"foo\":\"bar\"}"> <#assign m = test?eval> ${m.foo}  <#-- prints: bar --> 

fail in eval

<#assign test = "{\"foo\":null}"> <#assign m = test?eval> <#-- fail in eval --> ${m.foo}   

unfortunately (or... infuriatingly), ftl doesn't know concept of null (although might change 2.4). if manage create map json foo key exists associated value null (like create such map in java), ${m.foo} still fail. surely can write ${m.foo!'null'}, print null if there's no foo key @ all. maybe it's better if provide default value null-s during json evaluation:

<#function parsejson json>   <#local null = 'null'> <#-- null not keyword in ftl -->   <#return json?eval> </#function>  ${parsejson("{\"foo\":null}").foo}  <#-- prints null --> 

now, however, can't tell difference between "null" , null. if that's problem, chose odd default, '@@@null' or use macro indicator value , use ?is_macro test if value null (that hack useful json evaluation can't produce macros)...


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -