spring.travel.site.model.user.User.java Source code

Java tutorial

Introduction

Here is the source code for spring.travel.site.model.user.User.java

Source

/**
 * Copyright 2014 Andy Godwin
 *
 * 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.
 */
package spring.travel.site.model.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Optional;

public class User {

    private String id;

    private String firstName;

    private String lastName;

    private String username;

    // Would like this to be an Optional ... custom jackson deserializer?
    @JsonProperty(value = "address")
    private Address a;

    public User() {
    }

    public User(String id, String firstName, String lastName, String username, Optional<Address> address) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.username = username;
        this.a = address.orElse(null);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Address getA() {
        return a;
    }

    public void setA(Address a) {
        this.a = a;
    }

    @JsonIgnore
    public Optional<Address> getAddress() {
        return Optional.ofNullable(a);
    }

    @JsonIgnore
    public void setAddress(Optional<Address> address) {
        this.a = address.orElse(null);
    }
}