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

com.toedter.spring.hateoas.jsonapi.JsonApiModel Maven / Gradle / Ivy

/*
 * Copyright 2020 the original author or authors.
 *
 * 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
 *
 *      https://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 com.toedter.spring.hateoas.jsonapi;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import lombok.Getter;
import org.springframework.hateoas.Links;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.lang.Nullable;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class JsonApiModel extends RepresentationModel {

    private final RepresentationModel entity;

    @JsonIgnore
    @Getter
    private final Map relationships;

    @JsonIgnore
    @Getter
    private final List> includedEntities;

    @JsonIgnore
    @Getter
    private Map metaData;

    @JsonIgnore
    @Getter
    private final HashMap> sparseFieldsets;

    JsonApiModel(
            @Nullable RepresentationModel entity,
            @Nullable Map relationships,
            @Nullable List> includedEntities,
            @Nullable Map metadata,
            @Nullable Links links,
            @Nullable HashMap> sparseFieldsets) {

        this.entity = entity;
        this.relationships = relationships;
        this.includedEntities = includedEntities;
        this.metaData = metadata;
        this.sparseFieldsets = sparseFieldsets;

        if (links != null) {
            add(links);
        }
    }

    @Nullable
    @JsonUnwrapped
    public RepresentationModel getContent() {
        return entity;
    }

    public Map getAndRemoveMetaData() {
        final Map finalMetaData = this.metaData;
        this.metaData = null;
        return finalMetaData;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy