@@ -0,0 +1,2758 @@
+/**%0A * This file is part of the Gribbit Web Framework.%0A * %0A *     https://github.com/lukehutch/gribbit%0A * %0A * @author Luke Hutchison%0A * %0A * --%0A * %0A * @license Apache 2.0 %0A * %0A * Copyright 2015 Luke Hutchison%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A *     http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage gribbit.util;%0A%0Aimport gribbit.server.config.GribbitProperties;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0Aimport com.fasterxml.jackson.annotation.JsonAutoDetect;%0Aimport com.fasterxml.jackson.core.JsonFactory;%0Aimport com.fasterxml.jackson.core.JsonParseException;%0Aimport com.fasterxml.jackson.databind.JsonMappingException;%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.fasterxml.jackson.databind.SerializationFeature;%0A%0Apublic class JSONJackson %7B%0A%0A    // TODO: maybe try using https://github.com/jdereg/json-io instead for parsing JSON?%0A%0A    private static JsonFactory factory = new JsonFactory();%0A%0A    static ObjectMapper mapper = new ObjectMapper(factory);%0A    static %7B%0A        mapper.setVisibilityChecker(mapper.getSerializationConfig().getDefaultVisibilityChecker() //%0A                .withFieldVisibility(JsonAutoDetect.Visibility.PUBLIC_ONLY) //%0A                .withGetterVisibility(JsonAutoDetect.Visibility.NONE) //%0A                .withSetterVisibility(JsonAutoDetect.Visibility.NONE) //%0A                .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));%0A%0A        if (GribbitProperties.PRETTY_PRINT_JSON) %7B%0A            mapper.enable(SerializationFeature.INDENT_OUTPUT);%0A        %7D%0A        // mapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);%0A    %7D%0A%0A    public static %3CT%3E T jsonToObject(String jsonString, Class%3CT%3E klass) throws JsonParseException,%0A            JsonMappingException, IOException %7B%0A        return mapper.readValue(jsonString, klass);%0A    %7D%0A%0A    public static %3CT%3E T jsonToObject(InputStream inputStream, Class%3CT%3E klass) throws JsonParseException,%0A            JsonMappingException, IOException %7B%0A        return mapper.readValue(inputStream, klass);%0A    %7D%0A%0A    //    // Superceded by JSON.toJSON(), which respects @Private annotations etc. %0A    //    public static %3CT%3E String objectToJson(Object object) throws JsonProcessingException %7B%0A    //        return mapper.writeValueAsString(object);%0A    //    %7D%0A%0A%7D%0A

Rename class