StackItem { @JsonIgnore public ByteStringStackItem asByteString() { if (this instanceof ByteStringStackItem) { return (ByteStringStackItem) this; } throw new IllegalStateException("This stack item is not of type " + StackItemType.BYTE_STRING.jsonValue() + " but of " + this.type.jsonValue()); } StackItem();  StackItem(StackItemType type); StackItemType getType(); @JsonIgnore ByteStringStackItem asByteString(); @JsonIgnore PointerStackItem asPointer(); @JsonIgnore BooleanStackItem asBoolean(); @JsonIgnore IntegerStackItem asInteger(); @JsonIgnore BufferStackItem asBuffer(); @JsonIgnore ArrayStackItem asArray(); @JsonIgnore MapStackItem asMap(); @JsonIgnore StructStackItem asStruct(); @JsonIgnore Object asAny(); @JsonIgnore Object asInteropInterface();  }
@Test(expected = IllegalStateException.class) public void testThrowOnWrongCastByteString() throws IOException { StackItem rawItem = OBJECT_MAPPER.readValue("{\"type\":\"Integer\",\"value\":\"1124\"}", StackItem.class); rawItem.asByteString(); }