2

I have a String value field inside my object, but this field can be even true or false. Now the mapping create value: "true" like a String and this create problem with some angularjs ng-model mapping because it wants a boolean. There is a way to indicate to Spring/Jackson that the String with true or false must be without ""? Or you have some advice to converte easly this value to boolean? At the moment I'm initializing the value through javascript with code like this

if ($(element)[0].value == "true")
   $(element).iCheck('check');
else
   $(element).iCheck('update');

but it is a work-around and I have a problem with value change (I posted a question here). The only solution is to change this value into javascript? Thanks

luca
  • 3,248
  • 10
  • 66
  • 145

2 Answers2

1

You can customize how your data is serialized in Jackson. Then you can simply return the value as a boolean from the server.


EDIT re: 3 field vs string comment above

This is exactly what you should be handling on the server side with what your controller is returning. Make use of that layer and convert the value in a Jackson Mapper or straight up in the data access layer (makes your model consistent from that layer up).

Mark Cooper
  • 406
  • 3
  • 13
0

in java script you can use JSON.parse("true") it is return boolean value

console.log(true==JSON.parse("true")) //true

Gamsh
  • 545
  • 4
  • 21