/** * Factory method for constructing a node that represents JSON * String value */ public TextNode textNode(String text) { return TextNode.valueOf(text); }
/** Convert a map of string-valued properties to Json properties. */ Map<String,JsonNode> jsonProps(Map<String,String> stringProps) { Map<String,JsonNode> result = new LinkedHashMap<String,JsonNode>(); for (Map.Entry<String,String> e : stringProps.entrySet()) result.put(e.getKey(), TextNode.valueOf(e.getValue())); return result; }
/** * Set name-value pair properties for this type or field. */ public final S prop(String name, String val) { return prop(name, TextNode.valueOf(val)); }
/** * Adds a property with the given name <tt>name</tt> and * value <tt>value</tt>. Neither <tt>name</tt> nor <tt>value</tt> can be * <tt>null</tt>. It is illegal to add a property if another with * the same name but different value already exists in this schema. * * @param name The name of the property to add * @param value The value for the property to add */ public void addProp(String name, String value) { addProp(name, TextNode.valueOf(value)); }
/** Construct a message. */ private Message(String name, String doc, Map<String,?> propMap, Schema request) { super(MESSAGE_RESERVED); this.name = name; this.doc = doc; this.request = request; if (propMap != null) // copy props for (Map.Entry<String,?> prop : propMap.entrySet()) { Object value = prop.getValue(); this.addProp(prop.getKey(), value instanceof String ? TextNode.valueOf((String)value) : (JsonNode)value); } }
/** * Creates the class type field. * * @return the field */ private Field createClassTypeField() { List<String> classTypeSymbols = Arrays.asList(OBJECT, EVENT); Schema classTypeEnum = Schema.createEnum(CLASS_TYPE_TYPE_NAME, null, BASE_SCHEMA_FORM_NAMESPACE, classTypeSymbols); Field classTypeField = new Field(CLASS_TYPE, classTypeEnum, null, null); classTypeField.addProp(DISPLAY_NAME, "Class type"); JsonNodeFactory jsonFactory = JsonNodeFactory.instance; ArrayNode displayNamesNode = jsonFactory.arrayNode(); displayNamesNode.add(TextNode.valueOf("Object")); displayNamesNode.add(TextNode.valueOf("Event")); classTypeField.addProp(DISPLAY_NAMES, displayNamesNode); classTypeField.addProp(DISPLAY_PROMPT, "Select class type"); classTypeField.addProp(BY_DEFAULT, OBJECT); return classTypeField; }
/** * Creates the override strategy field. * * @return the field */ private Field createOverrideStrategyField() { List<String> overrideStrategySymbols = Arrays.asList(OverrideStrategy.APPEND.name(), OverrideStrategy.REPLACE.name()); Schema overrideStrategyEnum = Schema.createEnum(OVERRIDE_STRATEGY_TYPE_NAME, null, BASE_SCHEMA_FORM_NAMESPACE, overrideStrategySymbols); Field overrideStrategyField = new Field(OVERRIDE_STRATEGY, Schema.createUnion(Arrays.asList( overrideStrategyEnum, Schema.create(Type.NULL))), null, null); overrideStrategyField.addProp(DISPLAY_NAME, "Override strategy"); JsonNodeFactory jsonFactory = JsonNodeFactory.instance; ArrayNode displayNamesNode = jsonFactory.arrayNode(); displayNamesNode.add(TextNode.valueOf("Append")); displayNamesNode.add(TextNode.valueOf("Replace")); overrideStrategyField.addProp(DISPLAY_NAMES, displayNamesNode); overrideStrategyField.addProp(DISPLAY_PROMPT, "Select array override strategy"); return overrideStrategyField; }
/** * Factory method for constructing a node that represents JSON * String value */ public TextNode textNode(String text) { return TextNode.valueOf(text); }
/** * Factory method for constructing a node that represents JSON * String value */ public TextNode textNode(String text) { return TextNode.valueOf(text); }
/** * Factory method for constructing a node that represents JSON * String value */ public TextNode textNode(String text) { return TextNode.valueOf(text); }
/** * Factory method for constructing a node that represents Json * String value */ public TextNode textNode(String text) { return TextNode.valueOf(text); }
/** Convert a map of string-valued properties to Json properties. */ Map<String,JsonNode> jsonProps(Map<String,String> stringProps) { Map<String,JsonNode> result = new LinkedHashMap<String,JsonNode>(); for (Map.Entry<String,String> e : stringProps.entrySet()) result.put(e.getKey(), TextNode.valueOf(e.getValue())); return result; }
/** * Set name-value pair properties for this type or field. */ public final S prop(String name, String val) { return prop(name, TextNode.valueOf(val)); }
/** * Adds a property with the given name <tt>name</tt> and * value <tt>value</tt>. Neither <tt>name</tt> nor <tt>value</tt> can be * <tt>null</tt>. It is illegal to add a property if another with * the same name but different value already exists in this schema. * * @param name The name of the property to add * @param value The value for the property to add */ public void addProp(String name, String value) { addProp(name, TextNode.valueOf(value)); }
/** Construct a message. */ private Message(String name, String doc, Map<String,?> propMap, Schema request) { super(MESSAGE_RESERVED); this.name = name; this.doc = doc; this.request = request; if (propMap != null) // copy props for (Map.Entry<String,?> prop : propMap.entrySet()) { Object value = prop.getValue(); this.addProp(prop.getKey(), value instanceof String ? TextNode.valueOf((String)value) : (JsonNode)value); } }
@Before public void setUp() throws Exception { objectSpec = context.mock(ObjectSpecification.class); encodableFacet = context.mock(EncodableFacet.class); objectAdapter = context.mock(ObjectAdapter.class); representation = new JsonRepresentation(TextNode.valueOf("aString")); jsonValueEncoder = new JsonValueEncoder(); }
@Before public void setUp() throws Exception { objectSpec = context.mock(ObjectSpecification.class); encodableFacet = context.mock(EncodableFacet.class); objectAdapter = context.mock(ObjectAdapter.class); representation = new JsonRepresentation(TextNode.valueOf("aString")); jsonValueEncoder = new JsonValueEncoder(); }
@Before public void setUp() throws Exception { mockObjectSpec = context.mock(ObjectSpecification.class); mockEncodableFacet = context.mock(EncodableFacet.class); mockObjectAdapter = context.mock(ObjectAdapter.class); mockAdapterManager = context.mock(AdapterManager.class); JsonValueEncoder.testSetAdapterManager(mockAdapterManager); representation = new JsonRepresentation(TextNode.valueOf("aString")); }
@Test public void whenReprIsString() throws Exception { // given allowingObjectSpecHas(EncodableFacet.class, encodableFacet); allowingObjectSpecCorrespondingClassIs(String.class); representation = new JsonRepresentation(TextNode.valueOf("aString")); context.checking(new Expectations() { { one(encodableFacet).fromEncodedString("aString"); will(returnValue(objectAdapter)); } }); // when final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation); // then assertSame(objectAdapter, adapter); }
@Test public void whenReprIsString() throws Exception { // given allowingObjectSpecHas(EncodableFacet.class, encodableFacet); allowingObjectSpecCorrespondingClassIs(String.class); representation = new JsonRepresentation(TextNode.valueOf("aString")); context.checking(new Expectations() { { one(encodableFacet).fromEncodedString("aString"); will(returnValue(objectAdapter)); } }); // when final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation); // then assertSame(objectAdapter, adapter); }