All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.jsonoverlay.StringOverlay Maven / Gradle / Ivy

Go to download

A fork of RepreZen JsonOverlay with all dependencies and code generation removed

There is a newer version: 2.1.36
Show newest version
/*********************************************************************
 *  Copyright (c) 2017 ModelSolv, Inc. and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *     ModelSolv, Inc.
 *     - initial API and implementation and/or initial documentation
 **********************************************************************/
package com.networknt.jsonoverlay;

import com.fasterxml.jackson.databind.JsonNode;

public final class StringOverlay extends ScalarOverlay {

	private StringOverlay(JsonNode json, JsonOverlay parent, ReferenceManager refMgr) {
		super(json, parent, factory, refMgr);
	}

	private StringOverlay(String value, JsonOverlay parent, ReferenceManager refMgr) {
		super(value, parent, factory, refMgr);
	}

	@Override
	protected String _fromJson(JsonNode json) {
		return json.isTextual() ? json.textValue() : null;
	}

	@Override
	protected JsonNode _toJsonInternal(SerializationOptions options) {
		return value != null ? _jsonScalar(value) : _jsonMissing();
	}

	@Override
	protected OverlayFactory _getFactory() {
		return factory;
	}

	@Override
	public String toString() {
		// we don't want quotes here; the default rendering uses toJson, which does
		// include them.
		return value != null ? value : "";
	}

	public static OverlayFactory factory = new OverlayFactory() {

		@Override
		protected Class getOverlayClass() {
			return StringOverlay.class;
		}

		@Override
		public StringOverlay _create(String value, JsonOverlay parent, ReferenceManager refMgr) {
			return new StringOverlay(value, parent, refMgr);
		}

		@Override
		public StringOverlay _create(JsonNode json, JsonOverlay parent, ReferenceManager refMgr) {
			return new StringOverlay(json, parent, refMgr);
		}

	};

	public static Builder builder(JsonOverlay modelMember) {
		return new Builder(factory, modelMember);
	}

	public static JsonOverlay create(JsonOverlay modelMember) {
		return builder(modelMember).build();
	}

	public static JsonOverlay create(String value, JsonOverlay modelMember) {
		JsonOverlay result = create(modelMember);
		result._set(value);
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy