Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.lib.json; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.lang.reflect.*; |
| 5 | import java.util.*; |
| 6 | |
| 7 | public class BooleanHandler extends Handler { |
| 8 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 9 | @Override |
| 10 | void encode(Encoder app, Object object, Map<Object,Type> visited) throws IOException, Exception { |
| 11 | app.append(object.toString()); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 12 | } |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 13 | |
| 14 | @Override |
Stuart McCulloch | a21b9e8 | 2012-08-02 13:26:25 +0000 | [diff] [blame] | 15 | Object decode(Decoder dec, boolean s) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 16 | return s; |
| 17 | } |
| 18 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 19 | @Override |
Stuart McCulloch | a21b9e8 | 2012-08-02 13:26:25 +0000 | [diff] [blame] | 20 | Object decode(Decoder dec, String s) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 21 | return Boolean.parseBoolean(s); |
| 22 | } |
| 23 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 24 | @Override |
Stuart McCulloch | a21b9e8 | 2012-08-02 13:26:25 +0000 | [diff] [blame] | 25 | Object decode(Decoder dec, Number s) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 26 | return s.intValue() != 0; |
| 27 | } |
| 28 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 29 | @Override |
Stuart McCulloch | a21b9e8 | 2012-08-02 13:26:25 +0000 | [diff] [blame] | 30 | Object decode(Decoder dec) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 31 | return false; |
| 32 | } |
| 33 | |
| 34 | } |