fge / jackson-coreutils

JSON Pointer (RFC 6901) and numeric JSON equivalence for Jackson (2.2.x)
Other
22 stars 31 forks source link

JsonLoader tidy-up #6

Open alexanderdean opened 9 years ago

alexanderdean commented 9 years ago

Feel free to close, but this seemed a bit odd in JsonLoader:

        final Closer closer = Closer.create();
        final JsonNode ret;
        final InputStream in;

        try {
            in = closer.register(url.openStream());
            ret = READER.fromInputStream(in);
        } finally {
            closer.close();
        }

        return ret;
    }

    /**
     * Read a {@link JsonNode} from an URL.
     *
     * @param url The URL to fetch the JSON document from
     * @return The document at that URL
     * @throws IOException in case of network problems etc.
     */
    public static JsonNode fromURL(final URL url)
        throws IOException
    {
        return READER.fromInputStream(url.openStream());
    }

This would feel like a better way round:

        return fromURL(url);
    }

    /**
     * Read a {@link JsonNode} from an URL.
     *
     * @param url The URL to fetch the JSON document from
     * @return The document at that URL
     * @throws IOException in case of network problems etc.
     */
    public static JsonNode fromURL(final URL url)
        throws IOException
    {
        final Closer closer = Closer.create();
        final JsonNode ret;
        final InputStream in;

        try {
            in = closer.register(url.openStream());
            ret = READER.fromInputStream(in);
        } finally {
            closer.close();
        }

        return ret;
    }