Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null references for java numbers and flex

 
Morten Franorge
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our domain model, having a null value for certain numbers (Integer, Long and Double) have specific business meaning in our domain (different than 0). However, there is no way to represent nulls in action script. They are interpreted as NaN, but once a NaN is sent back to Java, it is not translated back to null. What is the best practise to handle this?
 
Satish Kore
Author
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Morten,

In ActionScript primitive types do not hold null value so anything that is Number,int or uint cannot hold null. Only Object or * type can hold null reference. There are two ways that I can see.

1. Simple approach would be just change type of ActionScript property from Number to Object and then if you assign null, it will be deserialized into null on java side.
2. Try not to use null as valid value, try using -1 or any negative value to represent your meaning.

Thanks,
 
Morten Franorge
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satish Kore wrote:Hi Morten,

In ActionScript primitive types do not hold null value so anything that is Number,int or uint cannot hold null. Only Object or * type can hold null reference. There are two ways that I can see.

1. Simple approach would be just change type of ActionScript property from Number to Object and then if you assign null, it will be deserialized into null on java side.
2. Try not to use null as valid value, try using -1 or any negative value to represent your meaning.

Thanks,


Option 2 require me to change the inherit functionality in my domain model, which does not sit well with the DDD. Option 1 makes the action script model sub optimal....hmmmm
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic