@Test public void testConvertChild_hintBoolean() throws Exception { ExpressionEvaluator eval = mock(ExpressionEvaluator.class); when(eval.evaluate(anyString())).thenAnswer(call -> call.getArgument(0, String.class)); assertSame("true is true", JsonValue.TRUE, converter().convertChild(xml("fooTrue.xml"), eval)); assertSame("true is true", JsonValue.TRUE, converter().convertChild(xml("fooTrue.xml", "boolean"), eval)); assertSame("non-boolean, empty string is false", JsonValue.FALSE, converter().convertChild(xml("emptyFoo.xml", "boolean"), eval)); assertSame("non-boolean, number is true", JsonValue.FALSE, converter().convertChild(xml("emptyFoo.xml", "boolean"), eval)); }
public JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator) throws ComponentConfigurationException { final Object value = fromExpression(child, evaluator); final String hint = child.getAttribute("hint"); if (hint != null) { switch (hint.toLowerCase()) { case HINT_MAP: return readJsonObjectFromConfig(child, evaluator); case HINT_LIST: return readJsonArrayFromConfig(child, evaluator); case HINT_STRING: return JavaxJson.wrap(String.valueOf(value)); case HINT_NUMBER: return JavaxJson.wrap(readNumberFromValue(child.getName(), value)); case HINT_BOOLEAN: return JavaxJson.wrap(readBooleanFromValue(child.getName(), value)); case HINT_VALUE_LITERAL: return readJsonValueFromValue(child.getName(), value); case HINT_OBJECT_LITERAL: return readJsonObjectFromValue(child.getName(), value); case HINT_ARRAY_LITERAL: return readJsonArrayFromValue(child.getName(), value); default: throw new ComponentConfigurationException("Unsupported JSON config hint type for key: " + child.getName() + ", hint=" + hint); } } else if (child.getChildCount() > 0) { if (mightBeList(child)) { return readJsonArrayFromConfig(child, evaluator); } else { return readJsonObjectFromConfig(child, evaluator); } } if (value instanceof String) { return JavaxJson.val(stringToValue((String) value)).get(); } return JavaxJson.val(value).get(); }
JsonConverter extends AbstractConfigurationConverter { public JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator) throws ComponentConfigurationException { final Object value = fromExpression(child, evaluator); final String hint = child.getAttribute("hint"); if (hint != null) { switch (hint.toLowerCase()) { case HINT_MAP: return readJsonObjectFromConfig(child, evaluator); case HINT_LIST: return readJsonArrayFromConfig(child, evaluator); case HINT_STRING: return JavaxJson.wrap(String.valueOf(value)); case HINT_NUMBER: return JavaxJson.wrap(readNumberFromValue(child.getName(), value)); case HINT_BOOLEAN: return JavaxJson.wrap(readBooleanFromValue(child.getName(), value)); case HINT_VALUE_LITERAL: return readJsonValueFromValue(child.getName(), value); case HINT_OBJECT_LITERAL: return readJsonObjectFromValue(child.getName(), value); case HINT_ARRAY_LITERAL: return readJsonArrayFromValue(child.getName(), value); default: throw new ComponentConfigurationException("Unsupported JSON config hint type for key: " + child.getName() + ", hint=" + hint); } } else if (child.getChildCount() > 0) { if (mightBeList(child)) { return readJsonArrayFromConfig(child, evaluator); } else { return readJsonObjectFromConfig(child, evaluator); } } if (value instanceof String) { return JavaxJson.val(stringToValue((String) value)).get(); } return JavaxJson.val(value).get(); } }
JsonConverter extends AbstractConfigurationConverter { public JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator) throws ComponentConfigurationException { final Object value = fromExpression(child, evaluator); final String hint = child.getAttribute("hint"); if (hint != null) { switch (hint.toLowerCase()) { case HINT_MAP: return readJsonObjectFromConfig(child, evaluator); case HINT_LIST: return readJsonArrayFromConfig(child, evaluator); case HINT_STRING: return JavaxJson.wrap(String.valueOf(value)); case HINT_NUMBER: return JavaxJson.wrap(readNumberFromValue(child.getName(), value)); case HINT_BOOLEAN: return JavaxJson.wrap(readBooleanFromValue(child.getName(), value)); case HINT_VALUE_LITERAL: return readJsonValueFromValue(child.getName(), value); case HINT_OBJECT_LITERAL: return readJsonObjectFromValue(child.getName(), value); case HINT_ARRAY_LITERAL: return readJsonArrayFromValue(child.getName(), value); default: throw new ComponentConfigurationException("Unsupported JSON config hint type for key: " + child.getName() + ", hint=" + hint); } } else if (child.getChildCount() > 0) { if (mightBeList(child)) { return readJsonArrayFromConfig(child, evaluator); } else { return readJsonObjectFromConfig(child, evaluator); } } if (value instanceof String) { return JavaxJson.val(stringToValue((String) value)).get(); } return JavaxJson.val(value).get(); }  }
JsonConverter extends AbstractConfigurationConverter { public JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator) throws ComponentConfigurationException { final Object value = fromExpression(child, evaluator); final String hint = child.getAttribute("hint"); if (hint != null) { switch (hint.toLowerCase()) { case HINT_MAP: return readJsonObjectFromConfig(child, evaluator); case HINT_LIST: return readJsonArrayFromConfig(child, evaluator); case HINT_STRING: return JavaxJson.wrap(String.valueOf(value)); case HINT_NUMBER: return JavaxJson.wrap(readNumberFromValue(child.getName(), value)); case HINT_BOOLEAN: return JavaxJson.wrap(readBooleanFromValue(child.getName(), value)); case HINT_VALUE_LITERAL: return readJsonValueFromValue(child.getName(), value); case HINT_OBJECT_LITERAL: return readJsonObjectFromValue(child.getName(), value); case HINT_ARRAY_LITERAL: return readJsonArrayFromValue(child.getName(), value); default: throw new ComponentConfigurationException("Unsupported JSON config hint type for key: " + child.getName() + ", hint=" + hint); } } else if (child.getChildCount() > 0) { if (mightBeList(child)) { return readJsonArrayFromConfig(child, evaluator); } else { return readJsonObjectFromConfig(child, evaluator); } } if (value instanceof String) { return JavaxJson.val(stringToValue((String) value)).get(); } return JavaxJson.val(value).get(); }  static String plexusPluralStem(final String key); @Override boolean canConvert(final Class<?> type); @Override Object fromConfiguration(final ConverterLookup lookup,
                                    final PlexusConfiguration configuration,
                                    final Class<?> type,
                                    final Class<?> enclosingType,
                                    final ClassLoader loader,
                                    final ExpressionEvaluator evaluator,
                                    final ConfigurationListener listener); JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator); static Object stringToValue(String string); }
JsonConverter extends AbstractConfigurationConverter { public JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator) throws ComponentConfigurationException { final Object value = fromExpression(child, evaluator); final String hint = child.getAttribute("hint"); if (hint != null) { switch (hint.toLowerCase()) { case HINT_MAP: return readJsonObjectFromConfig(child, evaluator); case HINT_LIST: return readJsonArrayFromConfig(child, evaluator); case HINT_STRING: return JavaxJson.wrap(String.valueOf(value)); case HINT_NUMBER: return JavaxJson.wrap(readNumberFromValue(child.getName(), value)); case HINT_BOOLEAN: return JavaxJson.wrap(readBooleanFromValue(child.getName(), value)); case HINT_VALUE_LITERAL: return readJsonValueFromValue(child.getName(), value); case HINT_OBJECT_LITERAL: return readJsonObjectFromValue(child.getName(), value); case HINT_ARRAY_LITERAL: return readJsonArrayFromValue(child.getName(), value); default: throw new ComponentConfigurationException("Unsupported JSON config hint type for key: " + child.getName() + ", hint=" + hint); } } else if (child.getChildCount() > 0) { if (mightBeList(child)) { return readJsonArrayFromConfig(child, evaluator); } else { return readJsonObjectFromConfig(child, evaluator); } } if (value instanceof String) { return JavaxJson.val(stringToValue((String) value)).get(); } return JavaxJson.val(value).get(); }  static String plexusPluralStem(final String key); @Override boolean canConvert(final Class<?> type); @Override Object fromConfiguration(final ConverterLookup lookup,
                                    final PlexusConfiguration configuration,
                                    final Class<?> type,
                                    final Class<?> enclosingType,
                                    final ClassLoader loader,
                                    final ExpressionEvaluator evaluator,
                                    final ConfigurationListener listener); JsonValue convertChild(final @NotNull PlexusConfiguration child, final ExpressionEvaluator evaluator); static Object stringToValue(String string);  }