Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.lib.json; |
| 2 | |
| 3 | import java.lang.reflect.*; |
| 4 | import java.util.*; |
| 5 | |
| 6 | public class CharacterHandler extends Handler { |
| 7 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 8 | @Override |
| 9 | void encode(Encoder app, Object object, Map<Object,Type> visited) throws Exception { |
| 10 | Character c = (Character) object; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 11 | int v = (int) c.charValue(); |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 12 | app.append(v + ""); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 13 | } |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 14 | |
| 15 | @Override |
| 16 | Object decode(boolean s) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 17 | return s ? 't' : 'f'; |
| 18 | } |
| 19 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 20 | @Override |
| 21 | Object decode(String s) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 22 | return (char) Integer.parseInt(s); |
| 23 | } |
| 24 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 25 | @Override |
| 26 | Object decode(Number s) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 27 | return (char) s.shortValue(); |
| 28 | } |
| 29 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 30 | @Override |
| 31 | Object decode() { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | } |