package com.codenetworkz.blog.config;


import com.codenetworkz.blog.dtos.TagDto;
import org.springframework.core.convert.converter.Converter;

public class StringToTagDtoConverter  implements Converter<String, TagDto> {

    private TagDto defaultTagDto = new TagDto();

    public StringToTagDtoConverter() {
        this.defaultTagDto = defaultTagDto;
    }

    @Override
    public TagDto convert(String source) {
        try {
            // Attempt to parse or convert the source string
            return new TagDto(Long.parseLong(source));
        } catch (Exception e) {
            // If conversion fails, return the default object
            return defaultTagDto;
        }
    }

}