RoleConverter.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */

package org.ctan.site.domain.account;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import lombok.NonNull;

/**
 * The class <code>RoleConverter</code> contains the converter from and to Role
 * values to strings.
 */
@Converter(autoApply = true)
public class RoleConverter implements AttributeConverter<Role, String> {

    /**
     * {@inheritDoc}
     *
     * @see jakarta.persistence.AttributeConverter#convertToDatabaseColumn(
     *     java.lang.Object)
     */
    @Override
    public String convertToDatabaseColumn(@NonNull Role role) {

        return role.toString();
    }

    /**
     * {@inheritDoc}
     *
     * @see jakarta.persistence.AttributeConverter#convertToEntityAttribute(
     *     java.lang.Object)
     */
    @Override
    public Role convertToEntityAttribute(@NonNull String value) {

        return Role.valueOf(value);
    }

}