001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * dmetzler 018 */ 019package org.nuxeo.ecm.automation.jaxrs.io; 020 021import java.io.IOException; 022import java.io.OutputStream; 023 024import org.nuxeo.ecm.webengine.JsonFactoryManager; 025import org.nuxeo.runtime.api.Framework; 026 027import com.fasterxml.jackson.core.JsonEncoding; 028import com.fasterxml.jackson.core.JsonFactory; 029import com.fasterxml.jackson.core.JsonGenerator; 030 031/** 032 * @since 5.7.3 033 */ 034public final class JsonHelper { 035 036 /** 037 * Helper method to centralize the JsonEncoding to use 038 */ 039 public static JsonGenerator createJsonGenerator(JsonFactory jsonFactory, OutputStream out) throws IOException { 040 return jsonFactory.createGenerator(out, JsonEncoding.UTF8); 041 } 042 043 public static JsonGenerator createJsonGenerator(OutputStream out) throws IOException { 044 JsonFactory jsonFactory = Framework.getService(JsonFactoryManager.class).getJsonFactory(); 045 return createJsonGenerator(jsonFactory, out); 046 } 047 048}