de.quantummaid.mapmaid.builder.injection.InjectionSerializer Maven / Gradle / Ivy
/*
* Copyright (c) 2020 Richard Hauswald - https://quantummaid.de/.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 de.quantummaid.mapmaid.builder.injection;
import de.quantummaid.mapmaid.debug.DebugInformation;
import de.quantummaid.mapmaid.debug.scaninformation.ScanInformation;
import de.quantummaid.mapmaid.mapper.serialization.SerializationCallback;
import de.quantummaid.mapmaid.mapper.serialization.serializers.TypeSerializer;
import de.quantummaid.mapmaid.mapper.serialization.tracker.SerializationTracker;
import de.quantummaid.mapmaid.mapper.universal.Universal;
import de.quantummaid.mapmaid.shared.identifier.TypeIdentifier;
import de.quantummaid.mapmaid.shared.mapping.CustomPrimitiveMappings;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import java.util.List;
import static de.quantummaid.mapmaid.debug.MapMaidException.mapMaidException;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class InjectionSerializer implements TypeSerializer {
private final TypeIdentifier typeIdentifier;
public static InjectionSerializer injectionSerializer(final TypeIdentifier typeIdentifier) {
return new InjectionSerializer(typeIdentifier);
}
@Override
public List requiredTypes() {
return emptyList();
}
@Override
public Universal serialize(final Object object,
final SerializationCallback callback,
final SerializationTracker tracker,
final CustomPrimitiveMappings customPrimitiveMappings,
final DebugInformation debugInformation) {
final ScanInformation scanInformation = debugInformation.scanInformationFor(this.typeIdentifier);
throw mapMaidException(format("Tried to serialize type '%s' that is marked as injection-only (input was '%s')",
this.typeIdentifier.description(), object), scanInformation);
}
@Override
public String description() {
return "always inject";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy