If I use generated jooq Java pojo, I cannot use it...
# http4k
r
If I use generated jooq Java pojo, I cannot use it in the OpenApi spec. Is this expected?
Copy code
returning(Status.OK, courseLocationsLens to exampleResponse)
Copy code
/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class CourseLocations implements Serializable {

    private static final long serialVersionUID = 1655656470;

    private final Integer id;
    private final String  building;
    private final String  room;

    public CourseLocations(CourseLocations value) {
        this.id = value.id;
        this.building = value.building;
        this.room = value.room;
    }

    public CourseLocations(
        Integer id,
        String  building,
        String  room
    ) {
        this.id = id;
        this.building = building;
        this.room = room;
    }

    public Integer getId() {
        return this.id;
    }

    public String getBuilding() {
        return this.building;
    }

    public String getRoom() {
        return this.room;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final CourseLocations other = (CourseLocations) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        }
        else if (!id.equals(other.id))
            return false;
        if (building == null) {
            if (other.building != null)
                return false;
        }
        else if (!building.equals(other.building))
            return false;
        if (room == null) {
            if (other.room != null)
                return false;
        }
        else if (!room.equals(other.room))
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
        result = prime * result + ((this.building == null) ? 0 : this.building.hashCode());
        result = prime * result + ((this.room == null) ? 0 : this.room.hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("CourseLocations (");

        sb.append(id);
        sb.append(", ").append(building);
        sb.append(", ").append(room);

        sb.append(")");
        return sb.toString();
    }
}
s
@Riku what error do you get? There’s nothing in http4k that’d prevent that AFAIK. Most likely that’s a limitation in the json library, as they tend to be picky about how the code should look like.
r
e.g.
I have not had trouble with serialization otherwise. The lens seems to work. I was missing some examples though and when I added them, I ran into these errors.
Well I replaced them with data classes for now
s
That seems like a limitation on how we resolve field names using reflection :(
d
@Riku are the field names capitalised? If so see the faq https://www.http4k.org/guide/modules/json/. you can also write a custom FieldRetreival and plug it into the OpenApi generator.
r
no, they are not
d
Have you got an example of the Json as well?
r
[{"name":"8-12","category":"AGE_GROUP","createdAt":"2020-09-18T10:03:25.429646"},{"name":"Ballet","category":"DANCE_TYPE","createdAt":"2020-09-18T10:03:25.429646"},{"name":"Kid","category":"AGE_GROUP","createdAt":"2020-10-17T21:39:53.879043"},{"name":"Test","category":"DANCE_LEVEL","createdAt":"2020-10-18T10:39:40.855793"},{"name":"Choreography","category":"SPECIAL_GROUP","createdAt":"2020-10-18T10:40:06.172039"},{"name":"Theatre","category":"UNKNOWN","createdAt":"2020-10-18T10:40:43.99458"}]
That is goes with the CourseTags error above.
d
That doesn't match the class you posted above..
If we can get the generated code as well I can try to take a look in a bit.
r
sorry that json was the switched out data class. But it works the same except there is an id field.
Copy code
/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class CourseTags implements Serializable {

    private static final long serialVersionUID = 1554583580;

    private final String            name;
    private final CourseTagCategory category;
    private final LocalDateTime     createdAt;

    public CourseTags(CourseTags value) {
        this.name = value.name;
        this.category = value.category;
        this.createdAt = value.createdAt;
    }

    public CourseTags(
        String            name,
        CourseTagCategory category,
        LocalDateTime     createdAt
    ) {
        this.name = name;
        this.category = category;
        this.createdAt = createdAt;
    }

    public String getName() {
        return this.name;
    }

    public CourseTagCategory getCategory() {
        return this.category;
    }

    public LocalDateTime getCreatedAt() {
        return this.createdAt;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final CourseTags other = (CourseTags) obj;
        if (name == null) {
            if (other.name != null)
                return false;
        }
        else if (!name.equals(other.name))
            return false;
        if (category == null) {
            if (other.category != null)
                return false;
        }
        else if (!category.equals(other.category))
            return false;
        if (createdAt == null) {
            if (other.createdAt != null)
                return false;
        }
        else if (!createdAt.equals(other.createdAt))
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
        result = prime * result + ((this.category == null) ? 0 : this.category.hashCode());
        result = prime * result + ((this.createdAt == null) ? 0 : this.createdAt.hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("CourseTags (");

        sb.append(name);
        sb.append(", ").append(category);
        sb.append(", ").append(createdAt);

        sb.append(")");
        return sb.toString();
    }
}
that is the generated code for course tag
d
Could you double check your meta block - the one you posted initially was using a different lens
r
ah not there is not id after all…
I am using Jackson and the lens for that was
Copy code
Body.auto<List<CourseTags>>().toLens()
Copy code
returning(OK, courseTagListOutLens to listOf(exampleTag))
d
If it's not a mistake, it doesnt look like our FieldRetreival works with java pojos. You can write a custom one and plug it in until we add it in the lib
r
Copy code
val exampleTag = CourseTags("Kids", CourseTagCategory.AGE_GROUP, LocalDateTime.now())
ok, it is not a big deal for me as I was only using the generated pojos in a few places. But thought I would raise a flag in case you are interested
d
Thanka for raising it. 🙃
@Riku JTLYK that I've just added support for JavaBeans now in the contract descriptors. Not releasing not, but it will be in 3.269.0 when that drops.
💪 1
r
David is Feature as a service. You rise an issue less than 4 hours later, he already added the implementation....
😂 1