com.memority.toolkit.rule.api.JsonSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-rule-api Show documentation
Show all versions of toolkit-rule-api Show documentation
This artifact provides the API classes that are necessary to implement the contracts of Memority configuration Rules.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Toolkit API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.toolkit.rule.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import static com.memority.toolkit.core.api.util.KitObjectMapperFactory.createStandardObjectMapper;
/**
* A simple helper function to serialize an object to its JSON representation in Groovy scripts.
*
* for example: {@code toJson(['id': OBJECT.id])} produces: {@code {"id": "myObjectId"}}
*/
public class JsonSerializer {
private final static ObjectMapper OBJECT_MAPPER = createStandardObjectMapper();
public static String toJson(Object object) throws JsonProcessingException {
return OBJECT_MAPPER.writeValueAsString(object);
}
}