@Test public void testStringToValue() { final String empty = ""; assertSame("same empty ", empty, JsonConverter.stringToValue(empty)); assertSame("same true", Boolean.TRUE, JsonConverter.stringToValue("true")); assertSame("same false", Boolean.FALSE, JsonConverter.stringToValue("false")); assertNull("same null", JsonConverter.stringToValue("null")); final String nan = "-NaN"; assertSame("same nan", nan, JsonConverter.stringToValue(nan)); assertEquals("read int", 42, JsonConverter.stringToValue("42")); assertEquals("read long", ((long) Integer.MAX_VALUE) + 1, JsonConverter.stringToValue(Long.toString(((long) Integer.MAX_VALUE) + 1))); assertEquals("read double", 42.0D, (double) JsonConverter.stringToValue("42.0"), 1.0D); assertEquals("maybe number? on second thought...", "-0foo", JsonConverter.stringToValue("-0foo")); }
public static Object stringToValue(String string) { if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return null; } char initial = string.charAt(0); if ((initial >= '0' && initial <= '9') || initial == '-') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || "-NaN".equals(string) || "-Infinity".equals(string) || string.indexOf('E') > -1 || "-0".equals(string)) { Double d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong.longValue() == myLong.intValue()) { return myLong.intValue(); } return myLong; } } } catch (Exception ignore) { } } return string; }
JsonConverter extends AbstractConfigurationConverter { public static Object stringToValue(String string) { if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return null; } char initial = string.charAt(0); if ((initial >= '0' && initial <= '9') || initial == '-') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || "-NaN".equals(string) || "-Infinity".equals(string) || string.indexOf('E') > -1 || "-0".equals(string)) { Double d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong.longValue() == myLong.intValue()) { return myLong.intValue(); } return myLong; } } } catch (Exception ignore) { } } return string; } }
JsonConverter extends AbstractConfigurationConverter { public static Object stringToValue(String string) { if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return null; } char initial = string.charAt(0); if ((initial >= '0' && initial <= '9') || initial == '-') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || "-NaN".equals(string) || "-Infinity".equals(string) || string.indexOf('E') > -1 || "-0".equals(string)) { Double d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong.longValue() == myLong.intValue()) { return myLong.intValue(); } return myLong; } } } catch (Exception ignore) { } } return string; }  }
JsonConverter extends AbstractConfigurationConverter { public static Object stringToValue(String string) { if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return null; } char initial = string.charAt(0); if ((initial >= '0' && initial <= '9') || initial == '-') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || "-NaN".equals(string) || "-Infinity".equals(string) || string.indexOf('E') > -1 || "-0".equals(string)) { Double d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong.longValue() == myLong.intValue()) { return myLong.intValue(); } return myLong; } } } catch (Exception ignore) { } } return string; }  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 static Object stringToValue(String string) { if (string.equals("")) { return string; } if (string.equalsIgnoreCase("true")) { return Boolean.TRUE; } if (string.equalsIgnoreCase("false")) { return Boolean.FALSE; } if (string.equalsIgnoreCase("null")) { return null; } char initial = string.charAt(0); if ((initial >= '0' && initial <= '9') || initial == '-') { try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || "-NaN".equals(string) || "-Infinity".equals(string) || string.indexOf('E') > -1 || "-0".equals(string)) { Double d = Double.valueOf(string); if (!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); if (string.equals(myLong.toString())) { if (myLong.longValue() == myLong.intValue()) { return myLong.intValue(); } return myLong; } } } catch (Exception ignore) { } } return string; }  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);  }