66

I couldn't find any explanation why StringEscapeUtils was deprecated from Apache Lang3 v3.7.

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html

What are we supposed to use now for HTML escaping/unescaping

gene b.
  • 10,512
  • 21
  • 115
  • 227
  • 12
    It's right there in the link you posted: `Deprecated. as of 3.6, use commons-text StringEscapeUtils instead` – Taylor Dec 14 '17 at 15:59

4 Answers4

125

The class was moved from package

org.apache.commons.lang3

to

org.apache.commons.text

You can replace the deprecated library easily:

In your build.gradle:

implementation 'org.apache.commons:commons-text:1.9'

And in your class using StringEscapeUtils make sure you import the correct class:

import org.apache.commons.text.StringEscapeUtils;

1.9 is currently the newest version (last checked February 24th 2021) but you can check the versions at maven: https://mvnrepository.com/artifact/org.apache.commons/commons-text

Björn Kechel
  • 7,933
  • 3
  • 54
  • 57
  • 3
    @user3871754 No, it is deprecated in the org.apache.commons.lang3 as it was adopted here in org.apache.commons.text as you can read here: http://commons.apache.org/proper/commons-text/javadocs/api-release/index.html (it clearly states "This code has been adapted from Apache Commons Lang 3.5.") – Björn Kechel Aug 22 '18 at 09:04
15

Per the deprecation listing, it was moved to a new project -- commons-text

Jamie Bisotti
  • 2,605
  • 19
  • 23
13

From Commons-lang 3.6 release notes:

The Apache Commons Community has recently set up the Commons Text component as a home for algorithms working on strings. For this reason most of the string focused functionality in Commons Lang has been deprecated and moved to Commons Text. This includes:

o All classes in the org.apache.commons.lang3.text and the org.apache.commons.lang3.text.translate packages o org.apache.commons.lang3.StringEscapeUtils o org.apache.commons.lang3.RandomStringUtils o The methods org.apache.commons.lang3.StringUtils.getJaroWinklerDistance and org.apache.commons.lang3.StringUtils.getLevenshteinDistance

For more information see the Commons Text website:

http://commons.apache.org/text
fn.
  • 2,788
  • 2
  • 27
  • 29
8

Do below steps

  • Add below dependency to your pom.xml (if using maven)
    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-text</artifactId>
       <version>1.4</version>
    <dependency>

  • Import correct package as below
    import org.apache.commons.text.StringEscapeUtils;

  • There is no such method unescapeHtml() in this class anymore, instead its two variations are available unescapeHtml3() and unescapeHtml4()
  • Use unescapeHtml3() to unescape Html 3.0 characters
  • Use unescapeHtml4() to unescape Html 4.0 characters
sapan prajapati
  • 1,514
  • 19
  • 16