001// Generated by delombok at Mon Oct 12 22:51:05 BST 2020 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020package org.apache.isis.viewer.restfulobjects.rendering.util; 021 022import java.io.IOException; 023import javax.annotation.Nullable; 024import org.apache.isis.core.config.environment.IsisSystemEnvironment; 025import org.apache.isis.viewer.restfulobjects.applib.util.JsonMapper; 026 027public final class JsonWriterUtil { 028 private JsonWriterUtil() { 029 } 030 031 public static String jsonFor(Object object, JsonMapper.PrettyPrinting prettyPrinting) { 032 try { 033 return JsonMapper.instance(prettyPrinting).write(object); 034 } catch (final IOException e) { 035 throw new RuntimeException(e); 036 } 037 } 038 039 public static String jsonFor(Object object, @Nullable IsisSystemEnvironment systemEnvironment) { 040 final org.apache.isis.viewer.restfulobjects.applib.util.JsonMapper.PrettyPrinting prettyPrinting = (systemEnvironment != null && systemEnvironment.isPrototyping()) ? JsonMapper.PrettyPrinting.ENABLE : JsonMapper.PrettyPrinting.DISABLE; 041 return jsonFor(object, prettyPrinting); 042 } 043}