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

de.jfachwert.util.ToFachwertSerializer.kt Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
/*
 * Copyright (c) 2018-2020 by Oliver Boehm
 *
 * 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.
 *
 * (c)reated 27.07.2018 by oboehm ([email protected])
 */
package de.jfachwert.util

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import de.jfachwert.KFachwert
import java.io.IOException

/**
 * Die Klasse serialisiert Fachwerte nach und von JSON. Damit die
 * Serialisierung funktioniert, muss
 * 
 * <groupId>com.fasterxml.jackson.core</groupId>
 * <artifactId>jackson-databind</artifactId>
 * 
* als Abhaengigkeit eingebunden werden. * * @author oboehm * @since 1.0 */ class ToFachwertSerializer @JvmOverloads constructor(t: Class = KFachwert::class.java) : StdSerializer(t) { /** * Fuer die Serialisierung wird der uebergebenen Fachwert nach seinen * einzelnen Elementen aufgeteilt und serialisiert. * * @param fachwert Fachwert * @param jgen Json-Generator * @param provider Provider * @throws IOException sollte nicht auftreten */ @Throws(IOException::class) override fun serialize(fachwert: KFachwert, jgen: JsonGenerator, provider: SerializerProvider) { serialize(fachwert.toMap(), jgen, provider) } @Throws(IOException::class) private fun serialize(map: Map, jgen: JsonGenerator, provider: SerializerProvider) { jgen.writeStartObject() for ((key, value) in map) { jgen.writeObjectField(key, value) } jgen.writeEndObject() } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy