Skip to content

Instantly share code, notes, and snippets.

View iamvickyav's full-sized avatar
😎
Savvy

Vicky AV iamvickyav

😎
Savvy
View GitHub Profile
public class User {
private Integer id;
private String name;
private Date dob;
private String city;
// constructors, getters & setters are ignored
}
// How to ignore fields in Java Object while serializing
// Approach 1 - @JsonIgnoreProperties
@JsonIgnoreProperties(value = {"id", "dob"})
public class User {
private Integer id;
private String name;
private Date dob;
@GetMapping(value = "/mockService/{serviceName}")
ResponseEntity fetchMockValue(@PathVariable("serviceName") String serviceName) throws IOException {
LOGGER.info("fetchMockValue called for serviceName={}", serviceName);
ResponseEntity responseEntity;
File mockServiceJsonFile = getFile(serviceName);
if(mockServiceJsonFile.exists()) {
String timeoutValue = environment.getProperty(serviceName + ".delay");
FROM openjdk:8-jre-slim
WORKDIR /home
COPY /target/UserManagement-1.0.jar UserManagement.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "UserManagement.jar"]
@iamvickyav
iamvickyav / Dockerfile
Last active May 17, 2020 18:12
Gradle & JRE in single Dockerfile using Docker Multi-build Feature
FROM gradle:jdk11 as gradleimage
COPY . /home/gradle/source
WORKDIR /home/gradle/source
RUN gradle build
FROM openjdk:11-jre-slim
COPY --from=gradleimage /home/gradle/source/build/libs/demo.jar /app/
WORKDIR /app
ENTRYPOINT ["java", "-jar", "demo.jar"]
@iamvickyav
iamvickyav / build.gradle
Created May 17, 2020 17:10
Jacoco configuration for Gradle
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.8.5'
}
test {
finalizedBy jacocoTestReport
}
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.Map;
@iamvickyav
iamvickyav / docker-compose.yml
Created March 5, 2020 13:50
docker-compose.yml for building DockerFile in current path
version: '3'
services:
app:
build: .
image: test-img
ports:
- 8080:8080
List<T> performRequest(ParameterizedTypeReference<List<T>> responseType) {
return restTemplate.exchange("http://www.mocky.io/v2/5e4d66ff2d0000309ec0df14",
HttpMethod.GET, null, responseType).getBody();
}
performRequest(new ParameterizedTypeReference<List<User>>() {});

application-.properties

Environment variable -> spring.profiles.active

application.properties is always loaded, irrespective of the spring.profiles.active value. If there is the same key-value present both in application.properties and application-.properties, the latter will override the former.