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

org.infinispan.schematic.internal.document.JsonWriter Maven / Gradle / Ivy

Go to download

Module for storing JSON/BSON documents and JSON Schemas in Infinispan

There is a newer version: 5.4.1.Final
Show newest version
/*
 * ModeShape (http://www.modeshape.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.infinispan.schematic.internal.document;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Pattern;
import org.infinispan.schematic.document.Binary;
import org.infinispan.schematic.document.Code;
import org.infinispan.schematic.document.CodeWithScope;
import org.infinispan.schematic.document.Document;
import org.infinispan.schematic.document.MaxKey;
import org.infinispan.schematic.document.MinKey;
import org.infinispan.schematic.document.ObjectId;
import org.infinispan.schematic.document.Symbol;
import org.infinispan.schematic.document.Timestamp;

/**
 * A component that writes modified JSON representations from the in-memory {@link Document} representation.
 * 

* The modified JSON format is nearly identical to the JSON serialization used by MongoDB. All standard JSON values are written as * expected, but the types unique to BSON are written as follows: *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
BSON TypeClassFormatExample
Symbol{@link Symbol}"value""The quick brown fox"
Regular Expression{@link Pattern}{ "$regex" : "pattern", "$options" : "flags" }{ "$regex" : "[CH]at\sin", "$options" : "im" }
Date{@link Date}{ "$date" : "yyyy-MM-ddTHH:mm:ssZ" }{ "$date" : "2011-06-11T08:44:25Z" }
Timestamp{@link Timestamp}{ "$ts" : timeValue, "$inc" : incValue }"\/TS("2011-06-11T08:44:25Z")\/"
ObjectId{@link ObjectId}{ "$oid" : "12bytesOfIdInBase16" }{ "$oid" : "0000012c0000c8000900000f" }
Binary{@link Binary}{ "$type" : typeAsInt, "$base64" : "bytesInBase64" }"{ "$type" : 0, "$base64" : "TWFuIGlzIGRpc3R" }"
UUID{@link UUID}{ "$uuid" : "string-form-of-uuid" }{ "$uuid" : "09e0e949-bba4-459c-bb1d-9352e5ee8958" }
Code{@link Code}{ "$code" : "code" }{ "$code" : "244-I2" }
CodeWithScope{@link CodeWithScope}{ "$code" : "code", "$scope" : scope document }{ "$code" : "244-I2", "$scope" : { "name" : "Joe" } }
MinKey{@link MinKey}"MinKey""MinKey"
MaxKey{@link MaxKey}"MaxKey""MaxKey"
Null valuenullnull
*

* * @author Randall Hauch (C) 2011 Red Hat Inc. * @since 5.1 */ public interface JsonWriter { /** * Write to the supplied stream the modified JSON representation of the supplied in-memory {@link Document}. * * @param object the BSON object or BSON value; may not be null * @param stream the output stream; may not be null * @throws IOException if there was a problem reading from the stream */ void write( Object object, OutputStream stream ) throws IOException; /** * Write to the supplied writer the modified JSON representation of the supplied in-memory {@link Document}. * * @param object the BSON object or BSON value; may not be null * @param writer the writer; may not be null * @throws IOException if there was a problem reading from the stream */ void write( Object object, Writer writer ) throws IOException; /** * Write to the supplied string builder the modified JSON representation of the supplied in-memory {@link Document} . * * @param object the BSON object or BSON value; may not be null * @param builder the string builder; may not be null */ void write( Object object, StringBuilder builder ); /** * Write and return the modified JSON representation of the supplied in-memory {@link Document}. * * @param object the BSON object or BSON value; may not be null * @return the JSON string representation; never null */ String write( Object object ); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy