| 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 |
* Container for opaque embedded Java objects, exposed by some non-JSON |
| 10 |
* backends: for example, binary formats would expose binary data natively |
| 11 |
* as such tokens. |
| 12 |
*/ |
| 13 |
public class JrsEmbeddedObject extends JrsValue.Scalar |
| 14 |
{ |
| 15 |
protected final Object _value; |
| 16 |
|
| 17 |
public JrsEmbeddedObject(Object v) { |
| 18 |
_value = v; |
| 19 |
} |
| 20 |
|
| 21 |
@Override |
| 22 |
public boolean isEmbeddedValue() { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
@Override |
| 27 |
public JsonToken asToken() { |
| 28 |
return JsonToken.VALUE_EMBEDDED_OBJECT; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public String asText() { |
| 33 |
return null; |
| 34 |
} |
| 35 |
|
| 36 |
/* |
| 37 |
/********************************************************************** |
| 38 |
/* Extended API |
| 39 |
/********************************************************************** |
| 40 |
*/ |
| 41 |
|
| 42 |
public Object embeddedValue() { |
| 43 |
return _value; |
| 44 |
} |
| 45 |
|
| 46 |
/* |
| 47 |
/********************************************************************** |
| 48 |
/* Abstract methods |
| 49 |
/********************************************************************** |
| 50 |
*/ |
| 51 |
|
| 52 |
@Override |
| 53 |
protected void write(JsonGenerator g, JacksonJrsTreeCodec codec) throws IOException { |
| 54 |
if (_value == null) { |
| 55 |
g.writeNull(); |
| 56 |
} else if (_value instanceof byte[]) { |
| 57 |
g.writeBinary((byte[]) _value); |
| 58 |
} else { |
| 59 |
g.writeObject(_value); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public boolean equals(Object o) { |
| 65 |
if (this == o) { |
| 66 |
return true; |
| 67 |
} |
| 68 |
if (o == null || getClass() != o.getClass()) { |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
JrsEmbeddedObject that = (JrsEmbeddedObject) o; |
| 73 |
|
| 74 |
return _value != null ? _value.equals(that._value) : that._value == null; |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public int hashCode() { |
| 79 |
return _value != null ? _value.hashCode() : 0; |
| 80 |
} |
| 81 |
} |