Skip to content

Commit 21550cd

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 162b3b2 + d81365a commit 21550cd

57 files changed

Lines changed: 749 additions & 356 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎gson/src/test/java/org/baeldung/gson/deserialization/GsonDeserializeTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.baeldung.gson.deserialization;
22

3-
import java.text.ParseException;
3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
45
import org.baeldung.gson.entities.ActorGson;
56
import org.baeldung.gson.entities.Movie;
67
import org.baeldung.gson.serialization.ActorGsonDeserializer;
78
import org.junit.Assert;
89
import org.junit.Test;
910

10-
import com.google.gson.Gson;
11-
import com.google.gson.GsonBuilder;
11+
import java.text.ParseException;
1212

1313
public class GsonDeserializeTest {
1414

‎gson/src/test/java/org/baeldung/gson/serialization/GsonSerializeTest.java‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package org.baeldung.gson.serialization;
22

3-
import java.text.ParseException;
4-
import java.text.SimpleDateFormat;
5-
import java.util.Arrays;
6-
3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import com.google.gson.JsonParser;
76
import org.baeldung.gson.entities.ActorGson;
87
import org.baeldung.gson.entities.Movie;
98
import org.baeldung.gson.entities.MovieWithNullValue;
10-
import org.baeldung.gson.serialization.ActorGsonDeserializer;
11-
import org.baeldung.gson.serialization.ActorGsonSerializer;
129
import org.junit.Assert;
1310
import org.junit.Test;
1411

15-
import com.google.gson.Gson;
16-
import com.google.gson.GsonBuilder;
17-
import com.google.gson.JsonParser;
12+
import java.text.ParseException;
13+
import java.text.SimpleDateFormat;
14+
import java.util.Arrays;
1815

1916
public class GsonSerializeTest {
2017

@@ -40,12 +37,12 @@ public void whenCustomSerialize_thenCorrect() throws ParseException {
4037
MovieWithNullValue movieWithNullValue = new MovieWithNullValue(null, "Mel Gibson", Arrays.asList(rudyYoungblood));
4138

4239
String expectedOutput = new GsonBuilder()
43-
.setPrettyPrinting()
44-
.serializeNulls()
45-
.disableHtmlEscaping()
46-
.create()
47-
.toJson(new JsonParser()
48-
.parse("{\"imdbId\":null,\"actors\":[{\"<strong>IMDB Code</strong>\":\"nm2199632\",\"<strong>Date Of Birth</strong>\":\"21-09-1982\",\"<strong>N° Film:</strong> \":3,\"filmography\":\"Apocalypto-Beatdown-Wind Walkers\"}]}"));
40+
.setPrettyPrinting()
41+
.serializeNulls()
42+
.disableHtmlEscaping()
43+
.create()
44+
.toJson(new JsonParser()
45+
.parse("{\"imdbId\":null,\"actors\":[{\"<strong>IMDB Code</strong>\":\"nm2199632\",\"<strong>Date Of Birth</strong>\":\"21-09-1982\",\"<strong>N° Film:</strong> \":3,\"filmography\":\"Apocalypto-Beatdown-Wind Walkers\"}]}"));
4946
Assert.assertEquals(gson.toJson(movieWithNullValue), expectedOutput);
5047
}
5148
}

‎jackson/src/test/java/org/baeldung/jackson/deserialization/JacksonDeserializeTest.java‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package org.baeldung.jackson.deserialization;
22

3-
import java.io.IOException;
4-
import java.text.DateFormat;
5-
import java.text.SimpleDateFormat;
3+
import com.fasterxml.jackson.databind.ObjectMapper;
64
import org.baeldung.jackson.entities.Movie;
75
import org.junit.Assert;
86
import org.junit.Test;
97

10-
import com.fasterxml.jackson.core.JsonParseException;
11-
import com.fasterxml.jackson.databind.JsonMappingException;
12-
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import java.io.IOException;
9+
import java.text.DateFormat;
10+
import java.text.SimpleDateFormat;
1311

1412
public class JacksonDeserializeTest {
1513

1614
@Test
17-
public void whenSimpleDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
15+
public void whenSimpleDeserialize_thenCorrect() throws IOException {
1816

1917
String jsonInput = "{\"imdbId\":\"tt0472043\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":\"1982-09-21T12:00:00+01:00\",\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}";
2018
ObjectMapper mapper = new ObjectMapper();
@@ -25,7 +23,7 @@ public void whenSimpleDeserialize_thenCorrect() throws JsonParseException, JsonM
2523
}
2624

2725
@Test
28-
public void whenCustomDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
26+
public void whenCustomDeserialize_thenCorrect() throws IOException {
2927

3028
String jsonInput = "{\"imdbId\":\"tt0472043\",\"director\":\"Mel Gibson\",\"actors\":[{\"imdbId\":\"nm2199632\",\"dateOfBirth\":\"1982-09-21T12:00:00+01:00\",\"filmography\":[\"Apocalypto\",\"Beatdown\",\"Wind Walkers\"]}]}";
3129

‎jsf/pom.xml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</dependency>
2828
<dependency>
2929
<groupId>javax.el</groupId>
30-
<artifactId>el-api</artifactId>
30+
<artifactId>javax.el-api</artifactId>
3131
<version>${javax.el.version}</version>
3232
</dependency>
3333

@@ -126,8 +126,8 @@
126126
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
127127

128128
<!-- JSF -->
129-
<com.sun.faces.version>2.1.7</com.sun.faces.version>
130-
<javax.el.version>2.2</javax.el.version>
129+
<com.sun.faces.version>2.2.13</com.sun.faces.version>
130+
<javax.el.version>3.0.0</javax.el.version>
131131

132132
<!-- logging -->
133133
<org.slf4j.version>1.7.13</org.slf4j.version>

‎jsf/src/main/java/com/baeldung/springintegration/controllers/ELSampleBean.java‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.baeldung.springintegration.controllers;
22

3-
import java.util.Random;
43
import javax.annotation.PostConstruct;
4+
import javax.el.ELContextEvent;
5+
import javax.el.ELContextListener;
6+
import javax.el.LambdaExpression;
57
import javax.faces.application.Application;
68
import javax.faces.application.FacesMessage;
9+
import javax.el.LambdaExpression;
710
import javax.faces.bean.ManagedBean;
811
import javax.faces.bean.ViewScoped;
9-
import javax.faces.component.html.HtmlInputText;
1012
import javax.faces.context.FacesContext;
13+
import java.util.Collection;
14+
import java.util.Random;
1115

1216
@ManagedBean(name = "ELBean")
1317
@ViewScoped
@@ -16,22 +20,37 @@ public class ELSampleBean {
1620
private String firstName;
1721
private String lastName;
1822
private String pageDescription = "This page demos JSF EL Basics";
23+
public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON";
1924
private int pageCounter;
2025
private Random randomIntGen = new Random();
2126

2227
@PostConstruct
2328
public void init() {
2429
pageCounter = randomIntGen.nextInt();
30+
FacesContext.getCurrentInstance().getApplication().addELContextListener(new ELContextListener() {
31+
@Override
32+
public void contextCreated(ELContextEvent evt) {
33+
evt.getELContext().getImportHandler().importClass("com.baeldung.springintegration.controllers.ELSampleBean");
34+
}
35+
});
2536
}
2637

2738
public void save() {
2839

2940
}
41+
42+
public static String constantField() {
43+
return constantField;
44+
}
3045

3146
public void saveFirstName(String firstName) {
3247
this.firstName = firstName;
3348
}
3449

50+
public Long multiplyValue(LambdaExpression expr) {
51+
Long theResult = (Long) expr.invoke(FacesContext.getCurrentInstance().getELContext(), pageCounter);
52+
return theResult;
53+
}
3554

3655
public void saveByELEvaluation() {
3756
firstName = (String) evaluateEL("#{firstName.value}", String.class);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:h="http://java.sun.com/jsf/html"
5+
xmlns:c="http://java.sun.com/jsp/jstl/core">
6+
<h:head>
7+
<title>Baeldung | Expression Language 3.0</title>
8+
</h:head>
9+
<h:body>
10+
<h:outputLabel id="valueLabel" for="valueOutput" value="Composite Lambda Evaluation:"/>
11+
<h:outputText id="valueOutput" value="#{(cube=(x->x*x*x);cube(4))}"/>
12+
<br/>
13+
<h:outputLabel id="staticLabel" for="staticFieldOutput" value="Static Field Output:"/>
14+
<h:outputText id="staticFieldOutput" value="#{ElBean.constantField}"/>
15+
<br/>
16+
<h:outputLabel id="avgLabel" for="avg" value="Average of Integer List Value:"/>
17+
<h:outputText id="avg" value="#{['1','2','3'].stream().average().get()}"/>
18+
<br/>
19+
<h:outputLabel id="lambdaLabel" for="lambdaPass" value="Passing Lambda Expressions:"/>
20+
<h:outputText id="lambdaPass" value="#{ELBean.multiplyValue(x->x*x*x)}"/>
21+
<br/>
22+
<c:set var='pageLevelNumberList' value="#{[1,2,3]}"/>
23+
<h:outputLabel id="avgPageVarLabel" for="avgPageVar" value="Average of Page-Level Integer List Value:"/>
24+
<h:outputText id="avgPageVar" value="#{pageLevelNumberList.stream().average().get()}"/>
25+
<br/>
26+
<h:panelGrid title="Data Structures" border="3" >
27+
<h:dataTable var="streamResult" value="#{pageLevelNumberList.stream().filter(x-> x>1).toList()}">
28+
<h:column id="nameCol">
29+
<h:outputText id="name" value="#{streamResult}"/>
30+
</h:column>
31+
</h:dataTable>
32+
</h:panelGrid>
33+
</h:body>
34+
</html>
35+

‎spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java‎

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.baeldung.main;
22

3-
import java.util.concurrent.ExecutorService;
4-
import java.util.concurrent.Executors;
5-
63
import org.baeldung.common.error.SpringHelloServletRegistrationBean;
74
import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator;
85
import org.baeldung.controller.servlet.HelloWorldServlet;
@@ -17,6 +14,9 @@
1714
import org.springframework.web.bind.annotation.RequestMapping;
1815
import org.springframework.web.bind.annotation.RestController;
1916

17+
import java.util.concurrent.ExecutorService;
18+
import java.util.concurrent.Executors;
19+
2020
@RestController
2121
@EnableAutoConfiguration
2222
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service" })
@@ -55,28 +55,6 @@ public SpringHelloServletRegistrationBean servletRegistrationBean() {
5555
return bean;
5656
}
5757

58-
/* @Bean
59-
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
60-
JettyEmbeddedServletContainerFactory jettyContainer = new JettyEmbeddedServletContainerFactory();
61-
jettyContainer.setPort(9000);
62-
jettyContainer.setContextPath("/springbootapp");
63-
return jettyContainer;
64-
}
65-
66-
@Bean
67-
public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
68-
UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();
69-
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
70-
71-
@Override
72-
public void customize(io.undertow.Undertow.Builde builder) {
73-
builder.addHttpListener(8080, "0.0.0.0");
74-
}
75-
76-
});
77-
return factory;
78-
}*/
79-
8058
@Bean
8159
@Autowired
8260
public ExecutorServiceExitCodeGenerator executorServiceExitCodeGenerator(ExecutorService executorService) {

0 commit comments

Comments
 (0)