Skip to content

Instantly share code, notes, and snippets.

View liptga's full-sized avatar

Gábor Lipták liptga

View GitHub Profile
@liptga
liptga / SerializationPuzzle
Created November 13, 2019 21:22
Serialization Puzzle
import org.springframework.util.SerializationUtils;
import java.io.Serializable;
public class SerializationPuzzle {
public static void main(String[] args) {
B deserialized = (B) SerializationUtils.deserialize(
SerializationUtils.serialize(new B("alma")));
System.out.println(deserialized.getText());
}
package at.liptakg.lombokdemo;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(exclude="fooo")
public class SideEffectExample {
private String bar;
private String fooo;
@Test
public void goodEquals() {
GoodEntityExample a = new GoodEntityExample("myfoo", 1, "excluded");
GoodEntityExample b = new GoodEntityExample("myfoo", 1, "does not matter");
assertThat( "Yeah. Works", a, is(b));
}
package at.liptakg.lombokdemo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper=false, exclude="name")
@AllArgsConstructor
public class GoodEntityExample extends POJO{
@Test
public void wrongEquals() {
WrongEntityExample a = new WrongEntityExample("myfoo", 1, "excluded");
WrongEntityExample b = new WrongEntityExample("myfoo", 1, "does not matter");
assertThat( "AAAAAAAA. Not equals :(", a, not(is(b)));
}
package at.liptakg.lombokdemo;
public class POJO
{
}
package at.liptakg.lombokdemo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper=true, exclude="name")
@AllArgsConstructor
public class WrongEntityExample extends POJO{
package at.liptakg.lombokdemo;
public class POJO
{
}
/**
Prints:
" "
"fdsajfklsdjalkf"
" "
"safd"
" "
"safsdfasdf"
" "
@liptga
liptga / RestTemplateConfiguration.java
Created August 30, 2017 12:17
RestTemplateConfiguration example with setting socket timeouts
@Configuration
public class RestTemplateConfiguration {
private static final String CUSTOM_HTTP_REQUEST_FACTORY_BEAN_NAME = "customHttpRequestFactory";
/**
* See https://stackoverflow.com/a/36991745/337621
* @return
*/
@Bean(CUSTOM_HTTP_REQUEST_FACTORY_BEAN_NAME)
@ConfigurationProperties(prefix = "rest.connection")