First use the @JsonFilter jackson annotation where you define an id of the filter

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

@JsonFilter("IndividualComparisonResultsFilter")
public class ComparisonResultBulk implements Serializable {

  //other fields ignored for brevity

  @JsonProperty("max_latency_millis")
  private String maxLatencyMillis;

  @JsonProperty("individual_comparison_results")
  private List<ComparisonResult> comparisonResults;

  @JsonProperty("not_comparable_results_size")
  private Integer notComparableResultsSize;

  @JsonProperty("not_comparable_results")
  private List<ComparisonResult> notComparableResults;
}

Then create a filterProvider, for example a SimpleFilterProvider for the id where you set the filter options.

In the example below everything is serialized except two properties with the help of SimpleBeanPropertyFilter.serializeAllExcept() method (serializeAll() is also present, and the opposite SimpleBeanPropertyFilter.filterOutAllExcept("individual_comparison_results", "not_comparable_results") which would serialize only these properties). In the end set the filterProvider set to the ObjectMapper where you serialize your object:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

private ComparisonReport generateReport(ComparisonResultBulk comparisonResultBulk)
      throws JsonProcessingException {
    ComparisonReport comparisonReport = new ComparisonReport();

    ObjectMapper mapper = new ObjectMapper();
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter("IndividualComparisonResultsFilter", SimpleBeanPropertyFilter.serializeAllExcept("individual_comparison_results", "not_comparable_results"));
    mapper.setFilterProvider(filterProvider);

    comparisonReport.setPayload(mapper.writeValueAsBytes(comparisonResultBulk));

    return comparisonReport;
}

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Use case

Some code snippets I save are really long or maybe too wide, due to comments of course, to read them easily in the code text area. In this case it is very practical to view them in full screen, a feature I implemented over the passing weekend:

Toggle fullscreen for snippets
Toggle fullscreen for snippets

For the implementation I used screenfull.js1, which is a simple wrapper for cross-browser usage of the JavaScript Fullscreen API2.

Let’s see how this goes exactly.

Continue Reading ...

Use the @Enumerated(EnumType.STRING) annotation:

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

@Entity
public class ComparisonReport implements Serializable {

  public static final String TABLE_NAME = "T_COMPARISON_REPORT";
  public static final String COLUMN_TRIGGER_TYPE = "TRIGGER_TYPE";

  @Column(name = COLUMN_TRIGGER_TYPE)
  @Enumerated(EnumType.STRING)
  private ReportTriggerType triggerType;

 //others ignored for brevity
}

The enum itself looks something the following

public enum ReportTriggerType {
    MANUAL("MANUAL"),
    AUTOMATIC("AUTOMATIC");

    private String value;

    ReportTriggerType(String source) {
      this.value = source;
    }

    public String getValue() {
      return value;
    }
  }

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

I usually set the date in the @PrePersist hook:

import javax.persistence.Entity;
import javax.persistence.PrePersist;
// others ignored for brevity


@Entity
public class ComparisonReport implements Serializable {

  public static final String TABLE_NAME = "T_COMPARISON_REPORT";
  public static final String COLUMN_CREATED_AT = "CREATED_AT";

  @Column(name = COLUMN_CREATED_AT)
  private LocalDateTime createdAt;

@PrePersist
  protected void prePersist() {
    if (this.createdAt == null) createdAt = LocalDateTime.now();
  }
 //others ignored for brevity
}

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Project: codever - File: howto-get-started.component.scss

Set margin-left and margin-right to auto to align in center of the page/div and text-align to align the text and image inside of the table headers and cells:

.extensions-table {
  margin-left: auto;
  margin-right: auto;
  th, td {
    width: 8rem;
    text-align: center;
  }
}
Continue Reading ...