| 1 |
package com.fasterxml.jackson.jr.stree; |
| 2 |
|
| 3 |
import java.io.IOException; |
| 4 |
|
| 5 |
import com.fasterxml.jackson.core.JsonGenerator; |
| 6 |
import com.fasterxml.jackson.core.JsonToken; |
| 7 |
|
| 8 |
/** |
| 9 |
* Virtual node used instead of `null`, when an operation does not match an |
| 10 |
* actual existing node; this can significantly simplify handling when no |
| 11 |
* null checks are needed. |
| 12 |
*/ |
| 13 |
public final class JrsNull extends JrsValue.Scalar |
| 14 |
{ |
| 15 |
final static JrsNull instance = new JrsNull(); |
| 16 |
|
| 17 |
public final static JrsNull instance() { |
| 18 |
return instance; |
| 19 |
} |
| 20 |
|
| 21 |
@Override |
| 22 |
public boolean isNull() { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
@Override |
| 27 |
public JsonToken asToken() { |
| 28 |
return JsonToken.VALUE_NULL; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public boolean equals(Object o) { |
| 33 |
return (o == this); |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public String toString() { |
| 38 |
// toString() should never return null |
| 39 |
return "null"; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public int hashCode() { |
| 44 |
return 3; |
| 45 |
} |
| 46 |
|
| 47 |
/* |
| 48 |
/********************************************************************** |
| 49 |
/* Abstract methods |
| 50 |
/********************************************************************** |
| 51 |
*/ |
| 52 |
|
| 53 |
@Override |
| 54 |
protected void write(JsonGenerator g, JacksonJrsTreeCodec codec) throws IOException { |
| 55 |
g.writeNull(); |
| 56 |
} |
| 57 |
} |