js-cookie/java-cookie is one of the server-side repositories TopGit tracks, currently at 63 stars, written primarily in Java. A simple Java API for handling cookies
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
IMPORTANT! when deleting a cookie, you must pass the exact same path, domain and secure attributes that were used to set the cookie, unless you're relying on the default attributes.
JSON Data Binding
java-cookie provides unobtrusive JSON storage for cookies with data binding.
When creating a cookie, you can pass a few supported types instead of String in the value. If you do so, java-cookie will store the stringified JSON representation of the value using jackson databind.
Consider the following class that implements the CookieValue interface:
public class Person implements CookieValue {
private int age;
public Person( int age ) {
this.age = age;
}
public int getAge() {
return age;
}
}
And the following usage:
Cookies cookies = Cookies.initFromServlet( request, response );
cookies.set( "name", new Person( 25 ) );
When reading a cookie with the default get() api, you receive the string representation stored in the cookie:
Cookies cookies = Cookies.initFromServlet( request, response );
String value = cookies.get( "name" ); // => "{\"age\":25}"
If you pass the type reference, it will parse the JSON into a new instance:
Cookies cookies = Cookies.initFromServlet( request, response );
Person adult = cookies.get( "name", Person.class );
if ( adult != null ) {
adult.getAge(); // => 25
}
Encoding
This project is RFC 6265 compliant. All special characters that are not allowed in the cookie-name or cookie-value are encoded with each one's UTF-8 Hex equivalent using percent-encoding.
The only character in cookie-name or cookie-value that is allowed and still encoded is the percent % character, it is escaped in order to interpret percent input as literal.
To override the default cookie decoding you need to use a converter.
Cookie Attributes
The default cookie attributes can be set globally by setting properties of the .defaults() instance or individually for each call to .set(...) by passing an Attributes instance in the last argument. Per-call attributes override the default attributes.
Define when the cookie will be removed. Value can be an Expiration.days() which will be interpreted as days from time of creation, a java.util.Date or an org.joda.time.DateTime instance. If omitted, the cookie becomes a session cookie.
Default: Cookie is removed when the user closes the browser.
Define whether your cookie should be restricted to a first party or same-site context
Default: not set
Note that more recent browsers are making "Lax" the default value even without specifying anything here.
Examples:
Cookies cookies = Cookies.initFromServlet( request, response );
cookies.set( "name", "value", Attributes.empty().sameSite( "Lax" ) );
cookies.get( "name" ); // => "value"
Converter
Create a new instance of the api that overrides the default decoding implementation.
All methods that rely in a proper decoding to work, such as remove() and get(), will run the converter first for each cookie.
The returning String will be used as the cookie value.
Example from reading one of the cookies that can only be decoded using the Javascript escape function:
// document.cookie = 'escaped=%u5317';
// document.cookie = 'default=%E5%8C%97';
Cookies cookies = Cookies.initFromServlet( request, response );
Cookies escapedCookies = cookies.withConverter(new Cookies.Converter() {
@Override
public String convert( String value, String name ) throws ConverterException {
ScriptEngine javascript = new ScriptEngineManager().getEngineByName( "JavaScript" );
if ( name.equals( "escaped" ) ) {
try {
return javascript.eval( "unescape('" + value + "')" ).toString();
} catch ( ScriptException e ) {
throw new ConverterException( e );
}
}
return null;
}
});
escapedCookies.get( "escaped" ); // => 北
escapedCookies.get( "default" ); // => 北
escapedCookies.get(); // => {escaped=北, default=北}
Instead of passing a converter inline, you can also create a custom strategy by implementing the ConverterStrategy interface:
class CustomConverter implements ConverterStrategy {
@Override
public String convert( String value, String name ) throws ConverterException {
return value;
}
}
Cookies cookies = Cookies.initFromServlet( request, response );
Cookies cookiesWithCustomConverter = cookies.withConverter( new CustomConverter() );
How active is development on js-cookie/java-cookie?
The most recent commit recorded on js-cookie/java-cookie was 3.9 years ago, based on the GitHub push timestamp. The repository has 21 forks — one of the better signals of community interest.
How does js-cookie/java-cookie compare to other Backend projects?
js-cookie/java-cookie is tracked by TopGit in the Backend category, with 63 GitHub stars and written in Java. Browse the Backend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does js-cookie/java-cookie have?
js-cookie/java-cookie has 63 GitHub stars — refresh the page for the live number, or check github.com/js-cookie/java-cookie. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What is js-cookie/java-cookie?
js-cookie/java-cookie (js-cookie/java-cookie) is a Java project on GitHub. From the project's own README: A simple Java API for handling cookies
What language is js-cookie/java-cookie written in?
js-cookie/java-cookie is written primarily in Java. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is js-cookie/java-cookie associated with?
GitHub's repository topics for js-cookie/java-cookie: "cookies", "java". TopGit's editorial category is Backend.
Why is js-cookie/java-cookie categorized under Backend?
TopGit places js-cookie/java-cookie in the Backend category based on its GitHub topics and description (tagged: "cookies", "java"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Curious whether java-cookie is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about java-cookie.